﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;

using Bricks.Component.Utils;
using Bricks.Business.Models;
using Bricks.Business.Models.FlowProcess;
using Bricks.Site.Models;
using Bricks.Business.Data.Repositories.ScheduleManagement;
using System.Xml;
using Bricks.Business.Service;
using Bricks.Business.Models.ScheduleManagement;
using System.Globalization;
using Bricks.Business.Data.Repositories.FlowProcess;
using Bricks.Component.Data;


namespace ChiDao.Business.Service.Impl
{
    [Export(typeof(IYearPlanService))]
    internal class YearPlanService : IYearPlanService
    {
        #region 属性
        [Import]
        protected IStatisticsItemMaintenanceRepository StatisticsItemMaintenanceRepository { get; set; }
        [Import]
        protected ITotalReviseRepository TotalReviseRepository { get; set; }
        [Import]
        protected ITotalReviseDetailsRepository TotalReviseDetailsRepository { get; set; }
        [Import]
        protected IYearPlanRepository YearPlanRepository { get; set; }
        [Import]
        protected IYearPlanDetailsRepository YearPlanDetailsRepository { get; set; }
        [Import]
        protected IYearPlanReviseRepository YearPlanReviseRepository { get; set; }
        [Import]
        protected IYearPlanReviseDetailsRepository YearPlanReviseDetailsRepository { get; set; }
        [Import]
        protected IBaklogTaskRepository BaklogTaskRepository { get; set; }
        #endregion

        public IQueryable<YearPlan> YearPlans
        {
            get { return YearPlanRepository.Entities; }
        }

        #region 公共私有函数
        //获取指定项目、合同类型和标段下总量维护修订金额
        public string GetTotalReviseMoney(Guid projectID, string contractType, Guid contractID)
        {
            string totalMoney = string.Empty;
            TotalRevise totalRevise = null;
            if (!string.IsNullOrEmpty(contractType))
            {
                totalRevise = TotalReviseRepository.Entities.Where(t => t.ProjectID == projectID && t.ContractType == contractType && t.ContractID == contractID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
            }
            else
            {
                totalRevise = TotalReviseRepository.Entities.Where(t => t.ProjectID == projectID && t.ContractID == contractID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
            }

            if (totalRevise != null)
            {
                totalMoney = totalRevise.ReviseMoney;
            }
            return totalMoney;
        }

        //主数据列表或者修订数据月统计
        private void CountMonthMoneyNum(string unit, string monthNum, ref decimal totalMoney)
        {
            if (!string.IsNullOrEmpty(monthNum))
            {
                if (unit == "万元")
                {
                    totalMoney += Convert.ToDecimal(monthNum);
                }
                else
                {
                    totalMoney += Convert.ToDecimal(monthNum) / 10000;
                }
            }
        }

        //主数据列表百分比计算
        private string CalculateMonthMoneyProportion(string totalMoneyStr, decimal money)
        {
            string proportion = string.Empty;
            if (!string.IsNullOrEmpty(totalMoneyStr) && money != 0)
            {
                decimal totalMoney = Convert.ToDecimal(totalMoneyStr);
                proportion = Math.Round(money * 100 / totalMoney, 1).ToString() + "%";
            }
            return proportion;
        }

        private string CalculateMonthMoneyProportionForPreview(string totalMoneyStr, string moneyStr)
        {
            string proportion = string.Empty;
            if (!string.IsNullOrEmpty(totalMoneyStr) && !string.IsNullOrEmpty(moneyStr))
            {
                decimal totalMoney = Convert.ToDecimal(totalMoneyStr);
                decimal money = Convert.ToDecimal(moneyStr);
                if (totalMoney > 0)
                {
                    proportion = Math.Round(money * 100 / totalMoney, 1).ToString() + "%";
                }
            }
            return proportion;
        }



        //获取指定项目、合同类型和标段下总量维护修订ID
        private Guid GetTotalReviseID(Guid projectID, string contractType, Guid contractID)
        {
            Guid reviseID = GuidHelper.NewGuid();
            TotalRevise totalRevise = TotalReviseRepository.Entities.Where(t => t.ProjectID == projectID && t.ContractType == contractType && t.ContractID == contractID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
            if (totalRevise != null)
            {
                reviseID = totalRevise.ID;
            }
            return reviseID;
        }

        //获取父统计项的名称
        private string GetParentStatisticsItemName(Guid? PID)
        {
            string parentStatisticsItemName = string.Empty;
            StatisticsItemMaintenance parentStatisticsItemMaintenance = StatisticsItemMaintenanceRepository.Entities.SingleOrDefault(s => s.ID == PID);
            if (parentStatisticsItemMaintenance != null)
            {
                parentStatisticsItemName = parentStatisticsItemMaintenance.StatisticsItemName;
            }
            return parentStatisticsItemName;
        }

        //明细数据列表工程量月统计
        private void CountEngineeringNumForDetails(string engineeringNum, ref string yearPlanAmount)
        {
            if (!string.IsNullOrEmpty(engineeringNum))
            {
                if (yearPlanAmount.Contains('/'))
                {
                    string[] totalEngineeringNumArr = yearPlanAmount.Split('/');
                    string[] engineeringNumArr = engineeringNum.Split('/');
                    if (engineeringNumArr.Length == 2)
                    {
                        yearPlanAmount = (Convert.ToDecimal(totalEngineeringNumArr[0]) + Convert.ToDecimal(engineeringNumArr[0])).ToString() + "/" + (Convert.ToDecimal(totalEngineeringNumArr[1]) + Convert.ToDecimal(engineeringNumArr[1])).ToString();
                    }
                    else if (engineeringNumArr.Length == 1)
                    {
                        yearPlanAmount = (Convert.ToDecimal(totalEngineeringNumArr[0]) + Convert.ToDecimal(engineeringNumArr[0])).ToString() + "/" + totalEngineeringNumArr[1];
                    }
                }
                else
                {
                    string[] engineeringNumArr = engineeringNum.Split('/');
                    if (engineeringNumArr.Length == 1)
                    {
                        yearPlanAmount = (Convert.ToDecimal(yearPlanAmount) + Convert.ToDecimal(engineeringNumArr[0])).ToString();
                    }
                    else if (engineeringNumArr.Length == 2)
                    {
                        yearPlanAmount = (Convert.ToDecimal(yearPlanAmount) + Convert.ToDecimal(engineeringNumArr[0])).ToString() + "/" + engineeringNumArr[1];
                    }
                }
            }
        }

        //明细数据列表工程量百分比计算
        private string CalculateMonthEngineeringProportionForDetails(string monthEngineeringNum, string yearPlanAmount, bool isMulUnit)
        {
            string proportion = string.Empty;
            if (!string.IsNullOrEmpty(monthEngineeringNum))
            {
                if (isMulUnit)
                {
                    string[] monthEngineeringNumArr = monthEngineeringNum.Split('/');
                    string[] totalEngineeringNumArr = yearPlanAmount.Split('/');
                    proportion = Math.Round(Convert.ToDecimal(monthEngineeringNumArr[0]) * 100 / Convert.ToDecimal(totalEngineeringNumArr[0]), 1).ToString() + "%";
                }
                else
                {
                    proportion = Math.Round(Convert.ToDecimal(monthEngineeringNum) * 100 / Convert.ToDecimal(yearPlanAmount), 1).ToString() + "%";
                }
            }
            return proportion;
        }

        //明细数据列表金额月统计
        private void CountMonthMoneyNumForDetails(string monthNum, ref decimal totalMoney)
        {
            if (!string.IsNullOrEmpty(monthNum))
            {
                totalMoney += Convert.ToDecimal(monthNum);
            }
        }

        //明细数据列表金额百分比计算
        private string CalculateMonthMoneyProportionForDetail(string monthMoneyNum, decimal yearPlanAmount)
        {
            string proportion = string.Empty;
            if (!string.IsNullOrEmpty(monthMoneyNum))
            {
                proportion = Math.Round(Convert.ToDecimal(monthMoneyNum) * 100 / yearPlanAmount, 1).ToString() + "%";
            }
            return proportion;
        }


        //为查看多标段的明细数据做统计
        private string TotalEngineeringOrMoneyNumForPreviewDetails(string originalValue, string countValue)
        {
            string returnValue = originalValue;
            if (!string.IsNullOrEmpty(countValue))
            {
                if (string.IsNullOrEmpty(originalValue))
                {
                    returnValue = countValue;
                }
                else
                {
                    if (originalValue.Contains('/'))
                    {
                        string[] originalValueArr = originalValue.Split('/');
                        string[] countValueArr = countValue.Split('/');
                        if (countValueArr.Length == 1)
                        {
                            returnValue = (Convert.ToDecimal(originalValueArr[0]) + Convert.ToDecimal(countValueArr[0])).ToString() + "/" + originalValueArr[1];
                        }
                        else if (countValueArr.Length == 2)
                        {
                            returnValue = (Convert.ToDecimal(originalValueArr[0]) + Convert.ToDecimal(countValueArr[0])).ToString() + "/" + (Convert.ToDecimal(originalValueArr[1]) + Convert.ToDecimal(countValueArr[1])).ToString();
                        }
                    }
                    else
                    {
                        string[] countValueArr = countValue.Split('/');
                        if (countValueArr.Length == 1)
                        {
                            returnValue = (Convert.ToDecimal(originalValue) + Convert.ToDecimal(countValueArr[0])).ToString();
                        }
                        else if (countValueArr.Length == 2)
                        {
                            returnValue = (Convert.ToDecimal(originalValue) + Convert.ToDecimal(countValueArr[0])).ToString() + "/" + countValueArr[1];
                        }
                    }
                }
            }
            return returnValue;
        }
        #endregion

        #region 主界面加载
        //申请人主数据列表
        public List<YearPlanView> GetYearPlanList(Guid projectID, string contractType, Guid contractID)
        {
            //获取总金额
            string totalMoney = GetTotalReviseMoney(projectID, contractType, contractID);

            //获取年度计划数据
            List<YearPlanView> lstYearPlanView = new List<YearPlanView>();
            var queryData = from yp in YearPlanRepository.Entities
                            where yp.ProjectID == projectID && yp.ContractType == contractType && yp.ContractID == contractID
                            orderby yp.StatisticalCycle descending
                            select yp;
            foreach (var item in queryData)
            {
                YearPlanView yearPlanView = new YearPlanView();
                yearPlanView.ID = item.ID;
                yearPlanView.FlowCode = item.FlowCode;
                yearPlanView.ProjectID = item.ProjectID;
                yearPlanView.ContractType = item.ContractType;
                yearPlanView.ContractID = item.ContractID;
                yearPlanView.StatisticalCycle = item.StatisticalCycle + "年";
                yearPlanView.Unit = item.Unit;
                yearPlanView.TotalMoney = totalMoney;

                var subQueryData = YearPlanDetailsRepository.Entities.Where(y => y.YearPlanID == item.ID);
                decimal januaryMoneyNum = 0;
                decimal februaryMoneyNum = 0;
                decimal marchMoneyNum = 0;
                decimal aprilMoneyNum = 0;
                decimal mayMoneyNum = 0;
                decimal juneMoneyNum = 0;
                decimal julyMoneyNum = 0;
                decimal augustMoneyNum = 0;
                decimal septemberMoneyNum = 0;
                decimal octoberMoneyNum = 0;
                decimal novemberMoneyNum = 0;
                decimal decemberMoneyNum = 0;
                foreach (var detailItem in subQueryData)
                {
                    StatisticsItemMaintenance statisticsItemMaintenance = StatisticsItemMaintenanceRepository.Entities.Single(s => s.ID == detailItem.StatisticsItemID);
                    if (statisticsItemMaintenance != null)
                    {
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JanuaryMoneyNum, ref januaryMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.FebruaryMoneyNum, ref februaryMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.MarchMoneyNum, ref marchMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.AprilMoneyNum, ref aprilMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.MayMoneyNum, ref mayMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JuneMoneyNum, ref juneMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JulyMoneyNum, ref julyMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.AugustMoneyNum, ref augustMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.SeptemberMoneyNum, ref septemberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.OctoberMoneyNum, ref octoberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.NovemberMoneyNum, ref novemberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.DecemberMoneyNum, ref decemberMoneyNum);
                    }
                }

                decimal yearPlanMoney = januaryMoneyNum + februaryMoneyNum + marchMoneyNum + aprilMoneyNum + mayMoneyNum + juneMoneyNum + julyMoneyNum + augustMoneyNum + septemberMoneyNum + octoberMoneyNum + novemberMoneyNum + decemberMoneyNum;
                yearPlanView.YearPlanMoney = yearPlanMoney == 0 ? string.Empty : yearPlanMoney.ToString();
                yearPlanView.YearPlanProportion = CalculateMonthMoneyProportion(totalMoney, yearPlanMoney);
                yearPlanView.JanuaryMoneyNum = januaryMoneyNum == 0 ? string.Empty : januaryMoneyNum.ToString();
                yearPlanView.JanuaryProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, januaryMoneyNum);
                yearPlanView.FebruaryMoneyNum = februaryMoneyNum == 0 ? string.Empty : februaryMoneyNum.ToString();
                yearPlanView.FebruaryProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, februaryMoneyNum);
                yearPlanView.MarchMoneyNum = marchMoneyNum == 0 ? string.Empty : marchMoneyNum.ToString();
                yearPlanView.MarchProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, marchMoneyNum);
                yearPlanView.AprilMoneyNum = aprilMoneyNum == 0 ? string.Empty : aprilMoneyNum.ToString();
                yearPlanView.AprilProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, aprilMoneyNum);
                yearPlanView.MayMoneyNum = mayMoneyNum == 0 ? string.Empty : mayMoneyNum.ToString();
                yearPlanView.MayProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, mayMoneyNum);
                yearPlanView.JuneMoneyNum = juneMoneyNum == 0 ? string.Empty : juneMoneyNum.ToString();
                yearPlanView.JuneProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, juneMoneyNum);
                yearPlanView.JulyMoneyNum = julyMoneyNum == 0 ? string.Empty : julyMoneyNum.ToString();
                yearPlanView.JulyProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, julyMoneyNum);
                yearPlanView.AugustMoneyNum = augustMoneyNum == 0 ? string.Empty : augustMoneyNum.ToString();
                yearPlanView.AugustProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, augustMoneyNum);
                yearPlanView.SeptemberMoneyNum = septemberMoneyNum == 0 ? string.Empty : septemberMoneyNum.ToString();
                yearPlanView.SeptemberProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, septemberMoneyNum);
                yearPlanView.OctoberMoneyNum = octoberMoneyNum == 0 ? string.Empty : octoberMoneyNum.ToString();
                yearPlanView.OctoberProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, octoberMoneyNum);
                yearPlanView.NovemberMoneyNum = novemberMoneyNum == 0 ? string.Empty : novemberMoneyNum.ToString();
                yearPlanView.NovemberProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, novemberMoneyNum);
                yearPlanView.DecemberMoneyNum = decemberMoneyNum == 0 ? string.Empty : decemberMoneyNum.ToString();
                yearPlanView.DecemberProportion = CalculateMonthMoneyProportion(yearPlanView.YearPlanMoney, decemberMoneyNum);

                lstYearPlanView.Add(yearPlanView);
            }
            return lstYearPlanView;
        }

        //申请人明细数据列表
        public List<YearPlanDetailsView> GetYearPlanDetailList(Guid projectID, string contractType, Guid contractID, Guid yearPlanID, bool isPreview = true)
        {
            //获取总量维护修订ID
            Guid reviseID = GetTotalReviseID(projectID, contractType, contractID);

            //获取总量维护修订明细
            var queryTotalReviseDetails = from td in TotalReviseDetailsRepository.Entities
                                          where td.TotalReviseID == reviseID
                                          select td;

            //获取年度计划明细
            var queryYearPlanDetails = from y in YearPlanDetailsRepository.Entities
                                       where y.YearPlanID == yearPlanID
                                       select y;

            var queryData = from s in StatisticsItemMaintenanceRepository.Entities
                            join td in queryTotalReviseDetails
                            on s.ID equals td.StatisticsItemID into joinedEmpTD
                            from tempTD in joinedEmpTD.DefaultIfEmpty()
                            join yd in queryYearPlanDetails
                            on s.ID equals yd.StatisticsItemID into joinedEmpYD
                            from tempYD in joinedEmpYD.DefaultIfEmpty()
                            where s.IsParent == false && s.ProjectID == projectID && s.ContractType == contractType
                            orderby s.OrderNo
                            select new
                            {
                                StatisticsItemID = s.ID,
                                s.StatisticsItemName,
                                s.PID,
                                s.EngineeringUnit,
                                s.MoneyUnit,
                                tempTD.EngineeringNum,
                                tempTD.MoneyNum,
                                YearPlanID = yearPlanID,
                                ID = tempYD == null ? Guid.NewGuid() : tempYD.ID,
                                tempYD.JanuaryEngineeringNum,
                                tempYD.JanuaryMoneyNum,
                                tempYD.FebruaryEngineeringNum,
                                tempYD.FebruaryMoneyNum,
                                tempYD.MarchEngineeringNum,
                                tempYD.MarchMoneyNum,
                                tempYD.AprilEngineeringNum,
                                tempYD.AprilMoneyNum,
                                tempYD.MayEngineeringNum,
                                tempYD.MayMoneyNum,
                                tempYD.JuneEngineeringNum,
                                tempYD.JuneMoneyNum,
                                tempYD.JulyEngineeringNum,
                                tempYD.JulyMoneyNum,
                                tempYD.AugustEngineeringNum,
                                tempYD.AugustMoneyNum,
                                tempYD.SeptemberEngineeringNum,
                                tempYD.SeptemberMoneyNum,
                                tempYD.OctoberEngineeringNum,
                                tempYD.OctoberMoneyNum,
                                tempYD.NovemberEngineeringNum,
                                tempYD.NovemberMoneyNum,
                                tempYD.DecemberEngineeringNum,
                                tempYD.DecemberMoneyNum
                            };

            List<YearPlanDetailsView> lstYearPlanDetailsView = new List<YearPlanDetailsView>();
            foreach (var item in queryData)
            {
                string parentStatisticsItemName = item.StatisticsItemName;
                if (item.PID != null)
                {
                    parentStatisticsItemName = GetParentStatisticsItemName(item.PID);
                }

                #region EngineeringUnit
                if (!string.IsNullOrEmpty(item.EngineeringUnit))
                {
                    YearPlanDetailsView yearPlanDetailsView = new YearPlanDetailsView();
                    yearPlanDetailsView.ID = item.ID;
                    yearPlanDetailsView.YearPlanID = item.YearPlanID;
                    yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                    yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                    yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                    yearPlanDetailsView.Unit = item.EngineeringUnit;
                    yearPlanDetailsView.TotalAmount = item.EngineeringNum;

                    yearPlanDetailsView.JanuaryAmount = item.JanuaryEngineeringNum;
                    yearPlanDetailsView.FebruaryAmount = item.FebruaryEngineeringNum;
                    yearPlanDetailsView.MarchAmount = item.MarchEngineeringNum;
                    yearPlanDetailsView.AprilAmount = item.AprilEngineeringNum;
                    yearPlanDetailsView.MayAmount = item.MayEngineeringNum;
                    yearPlanDetailsView.JuneAmount = item.JuneEngineeringNum;
                    yearPlanDetailsView.JulyAmount = item.JulyEngineeringNum;
                    yearPlanDetailsView.AugustAmount = item.AugustEngineeringNum;
                    yearPlanDetailsView.SeptemberAmount = item.SeptemberEngineeringNum;
                    yearPlanDetailsView.OctoberAmount = item.OctoberEngineeringNum;
                    yearPlanDetailsView.NovemberAmount = item.NovemberEngineeringNum;
                    yearPlanDetailsView.DecemberAmount = item.DecemberEngineeringNum;

                    if (isPreview)
                    {
                        if (!string.IsNullOrEmpty(item.JanuaryEngineeringNum) || !string.IsNullOrEmpty(item.FebruaryEngineeringNum) ||
                            !string.IsNullOrEmpty(item.MarchEngineeringNum) || !string.IsNullOrEmpty(item.AprilEngineeringNum) ||
                            !string.IsNullOrEmpty(item.MayEngineeringNum) || !string.IsNullOrEmpty(item.JuneEngineeringNum) ||
                            !string.IsNullOrEmpty(item.JulyEngineeringNum) || !string.IsNullOrEmpty(item.AugustEngineeringNum) ||
                            !string.IsNullOrEmpty(item.SeptemberEngineeringNum) || !string.IsNullOrEmpty(item.OctoberEngineeringNum) ||
                            !string.IsNullOrEmpty(item.NovemberEngineeringNum) || !string.IsNullOrEmpty(item.DecemberEngineeringNum))
                        {
                            bool isMulUnit = false;
                            string yearPlanAmount = "0";
                            if (item.EngineeringUnit.Contains('/'))
                            {
                                yearPlanAmount = "0/0";
                                isMulUnit = true;
                            }
                            CountEngineeringNumForDetails(item.JanuaryEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.FebruaryEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.MarchEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.AprilEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.MayEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.JuneEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.JulyEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.AugustEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.SeptemberEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.OctoberEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.NovemberEngineeringNum, ref yearPlanAmount);
                            CountEngineeringNumForDetails(item.DecemberEngineeringNum, ref yearPlanAmount);

                            yearPlanDetailsView.YearPlanAmount = yearPlanAmount;
                            if (!string.IsNullOrEmpty(item.EngineeringNum))
                            {
                                if (isMulUnit)
                                {
                                    string[] yearPlanAmountArr = yearPlanAmount.Split('/');
                                    string[] totalAmountArr = item.EngineeringNum.Split('/');

                                    yearPlanDetailsView.YearPlanProportion = Math.Round(Convert.ToDecimal(yearPlanAmountArr[0]) * 100 / Convert.ToDecimal(totalAmountArr[0]), 1).ToString() + "%";
                                }
                                else
                                {
                                    yearPlanDetailsView.YearPlanProportion = Math.Round(Convert.ToDecimal(yearPlanAmount) * 100 / Convert.ToDecimal(item.EngineeringNum), 1).ToString() + "%";
                                }
                            }

                            yearPlanDetailsView.JanuaryProportion = CalculateMonthEngineeringProportionForDetails(item.JanuaryEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.FebruaryProportion = CalculateMonthEngineeringProportionForDetails(item.FebruaryEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.MarchProportion = CalculateMonthEngineeringProportionForDetails(item.MarchEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.AprilProportion = CalculateMonthEngineeringProportionForDetails(item.AprilEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.MayProportion = CalculateMonthEngineeringProportionForDetails(item.MayEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.JuneProportion = CalculateMonthEngineeringProportionForDetails(item.JuneEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.JulyProportion = CalculateMonthEngineeringProportionForDetails(item.JulyEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.AugustProportion = CalculateMonthEngineeringProportionForDetails(item.AugustEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.SeptemberProportion = CalculateMonthEngineeringProportionForDetails(item.SeptemberEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.OctoberProportion = CalculateMonthEngineeringProportionForDetails(item.OctoberEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.NovemberProportion = CalculateMonthEngineeringProportionForDetails(item.NovemberEngineeringNum, yearPlanAmount, isMulUnit);
                            yearPlanDetailsView.DecemberProportion = CalculateMonthEngineeringProportionForDetails(item.DecemberEngineeringNum, yearPlanAmount, isMulUnit);
                        }
                    }
                    yearPlanDetailsView.IsBelongToMoneyNum = "0";
                    lstYearPlanDetailsView.Add(yearPlanDetailsView);
                }
                #endregion

                #region MoneyUnit
                if (!string.IsNullOrEmpty(item.MoneyUnit))
                {
                    YearPlanDetailsView yearPlanDetailsView = new YearPlanDetailsView();
                    yearPlanDetailsView.ID = item.ID;
                    yearPlanDetailsView.YearPlanID = item.YearPlanID;
                    yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                    yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                    yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                    yearPlanDetailsView.Unit = item.MoneyUnit;
                    yearPlanDetailsView.TotalAmount = item.MoneyNum;

                    yearPlanDetailsView.JanuaryAmount = item.JanuaryMoneyNum;
                    yearPlanDetailsView.FebruaryAmount = item.FebruaryMoneyNum;
                    yearPlanDetailsView.MarchAmount = item.MarchMoneyNum;
                    yearPlanDetailsView.AprilAmount = item.AprilMoneyNum;
                    yearPlanDetailsView.MayAmount = item.MayMoneyNum;
                    yearPlanDetailsView.JuneAmount = item.JuneMoneyNum;
                    yearPlanDetailsView.JulyAmount = item.JulyMoneyNum;
                    yearPlanDetailsView.AugustAmount = item.AugustMoneyNum;
                    yearPlanDetailsView.SeptemberAmount = item.SeptemberMoneyNum;
                    yearPlanDetailsView.OctoberAmount = item.OctoberMoneyNum;
                    yearPlanDetailsView.NovemberAmount = item.NovemberMoneyNum;
                    yearPlanDetailsView.DecemberAmount = item.DecemberMoneyNum;

                    if (isPreview)
                    {
                        if (!string.IsNullOrEmpty(item.JanuaryMoneyNum) || !string.IsNullOrEmpty(item.FebruaryMoneyNum) ||
                            !string.IsNullOrEmpty(item.MarchMoneyNum) || !string.IsNullOrEmpty(item.AprilMoneyNum) ||
                            !string.IsNullOrEmpty(item.MayMoneyNum) || !string.IsNullOrEmpty(item.JuneMoneyNum) ||
                            !string.IsNullOrEmpty(item.JulyMoneyNum) || !string.IsNullOrEmpty(item.AugustMoneyNum) ||
                            !string.IsNullOrEmpty(item.SeptemberMoneyNum) || !string.IsNullOrEmpty(item.OctoberMoneyNum) ||
                            !string.IsNullOrEmpty(item.NovemberMoneyNum) || !string.IsNullOrEmpty(item.DecemberMoneyNum))
                        {
                            decimal yearPlanAmount = 0;
                            CountMonthMoneyNumForDetails(item.JanuaryMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.FebruaryMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.MarchMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.AprilMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.MayMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.JuneMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.JulyMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.AugustMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.SeptemberMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.OctoberMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.NovemberMoneyNum, ref yearPlanAmount);
                            CountMonthMoneyNumForDetails(item.DecemberMoneyNum, ref yearPlanAmount);
                            yearPlanDetailsView.YearPlanAmount = yearPlanAmount.ToString();
                            if (!string.IsNullOrEmpty(item.MoneyNum))
                            {
                                yearPlanDetailsView.YearPlanProportion = Math.Round(yearPlanAmount * 100 / Convert.ToDecimal(item.MoneyNum), 1).ToString() + "%";
                            }

                            yearPlanDetailsView.JanuaryProportion = CalculateMonthMoneyProportionForDetail(item.JanuaryMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.FebruaryProportion = CalculateMonthMoneyProportionForDetail(item.FebruaryMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.MarchProportion = CalculateMonthMoneyProportionForDetail(item.MarchMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.AprilProportion = CalculateMonthMoneyProportionForDetail(item.AprilMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.MayProportion = CalculateMonthMoneyProportionForDetail(item.MayMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.JuneProportion = CalculateMonthMoneyProportionForDetail(item.JuneMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.JulyProportion = CalculateMonthMoneyProportionForDetail(item.JulyMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.AugustProportion = CalculateMonthMoneyProportionForDetail(item.AugustMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.SeptemberProportion = CalculateMonthMoneyProportionForDetail(item.SeptemberMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.OctoberProportion = CalculateMonthMoneyProportionForDetail(item.OctoberMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.NovemberProportion = CalculateMonthMoneyProportionForDetail(item.NovemberMoneyNum, yearPlanAmount);
                            yearPlanDetailsView.DecemberProportion = CalculateMonthMoneyProportionForDetail(item.DecemberMoneyNum, yearPlanAmount);
                        }
                    }
                    yearPlanDetailsView.IsBelongToMoneyNum = "1";
                    lstYearPlanDetailsView.Add(yearPlanDetailsView);
                }
                #endregion
            }
            return lstYearPlanDetailsView;
        }

        //修订下拉列表
        public List<YearPlanView> GetYearPlanReviseList(Guid yearPlanID)
        {
            List<YearPlanView> lstYearPlanView = new List<YearPlanView>();
            var queryTotalRevise = from y in YearPlanReviseRepository.Entities
                                   where y.YearPlanID == yearPlanID
                                   orderby y.ReviseDate descending
                                   select y;
            lstYearPlanView.Add(new YearPlanView() { YearPlanReviseID = Guid.Empty, ReviseDisplay = "流程数据" });
            foreach (var item in queryTotalRevise)
            {
                lstYearPlanView.Add(new YearPlanView() { YearPlanReviseID = item.ID, ReviseDisplay = "第" + item.ReviseNum.ToString() + "次" + item.ReviseDate.ToString("yyyy年MM月dd日", DateTimeFormatInfo.InvariantInfo) + ",总金额" + item.ReviseMoney + "万元" });
            }
            return lstYearPlanView;
        }

        //选中修订记录明细数据列表
        public List<YearPlanDetailsView> GetYearPlanReviseDetailList(Guid projectID, string contractType, Guid contractID, Guid yearPlanReviseID)
        {
            //获取总量维护修订ID
            Guid reviseID = GetTotalReviseID(projectID, contractType, contractID);

            //获取总量维护修订明细
            var queryTotalReviseDetails = from td in TotalReviseDetailsRepository.Entities
                                          where td.TotalReviseID == reviseID
                                          select td;

            //获取年度计划修订明细
            var queryYearPlanReviseDetails = from y in YearPlanReviseDetailsRepository.Entities
                                             where y.YearPlanReviseID == yearPlanReviseID
                                             select y;

            var queryData = from s in StatisticsItemMaintenanceRepository.Entities
                            join td in queryTotalReviseDetails
                            on s.ID equals td.StatisticsItemID into joinedEmpTD
                            from tempTD in joinedEmpTD.DefaultIfEmpty()
                            join yd in queryYearPlanReviseDetails
                            on s.ID equals yd.StatisticsItemID into joinedEmpYD
                            from tempYD in joinedEmpYD.DefaultIfEmpty()
                            where s.IsParent == false && s.ProjectID == projectID && s.ContractType == contractType
                            orderby s.OrderNo
                            select new
                            {
                                StatisticsItemID = s.ID,
                                s.StatisticsItemName,
                                s.PID,
                                s.EngineeringUnit,
                                s.MoneyUnit,
                                tempTD.EngineeringNum,
                                tempTD.MoneyNum,
                                ID = tempYD == null ? Guid.NewGuid() : tempYD.ID,
                                tempYD.JanuaryEngineeringNum,
                                tempYD.JanuaryMoneyNum,
                                tempYD.FebruaryEngineeringNum,
                                tempYD.FebruaryMoneyNum,
                                tempYD.MarchEngineeringNum,
                                tempYD.MarchMoneyNum,
                                tempYD.AprilEngineeringNum,
                                tempYD.AprilMoneyNum,
                                tempYD.MayEngineeringNum,
                                tempYD.MayMoneyNum,
                                tempYD.JuneEngineeringNum,
                                tempYD.JuneMoneyNum,
                                tempYD.JulyEngineeringNum,
                                tempYD.JulyMoneyNum,
                                tempYD.AugustEngineeringNum,
                                tempYD.AugustMoneyNum,
                                tempYD.SeptemberEngineeringNum,
                                tempYD.SeptemberMoneyNum,
                                tempYD.OctoberEngineeringNum,
                                tempYD.OctoberMoneyNum,
                                tempYD.NovemberEngineeringNum,
                                tempYD.NovemberMoneyNum,
                                tempYD.DecemberEngineeringNum,
                                tempYD.DecemberMoneyNum
                            };

            List<YearPlanDetailsView> lstYearPlanDetailsView = new List<YearPlanDetailsView>();
            foreach (var item in queryData)
            {
                string parentStatisticsItemName = item.StatisticsItemName;
                if (item.PID != null)
                {
                    parentStatisticsItemName = GetParentStatisticsItemName(item.PID);
                }

                #region EngineeringUnit
                if (!string.IsNullOrEmpty(item.EngineeringUnit))
                {
                    YearPlanDetailsView yearPlanDetailsView = new YearPlanDetailsView();
                    yearPlanDetailsView.ID = item.ID;
                    yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                    yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                    yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                    yearPlanDetailsView.Unit = item.EngineeringUnit;
                    yearPlanDetailsView.TotalAmount = item.EngineeringNum;

                    yearPlanDetailsView.JanuaryAmount = item.JanuaryEngineeringNum;
                    yearPlanDetailsView.FebruaryAmount = item.FebruaryEngineeringNum;
                    yearPlanDetailsView.MarchAmount = item.MarchEngineeringNum;
                    yearPlanDetailsView.AprilAmount = item.AprilEngineeringNum;
                    yearPlanDetailsView.MayAmount = item.MayEngineeringNum;
                    yearPlanDetailsView.JuneAmount = item.JuneEngineeringNum;
                    yearPlanDetailsView.JulyAmount = item.JulyEngineeringNum;
                    yearPlanDetailsView.AugustAmount = item.AugustEngineeringNum;
                    yearPlanDetailsView.SeptemberAmount = item.SeptemberEngineeringNum;
                    yearPlanDetailsView.OctoberAmount = item.OctoberEngineeringNum;
                    yearPlanDetailsView.NovemberAmount = item.NovemberEngineeringNum;
                    yearPlanDetailsView.DecemberAmount = item.DecemberEngineeringNum;

                    if (!string.IsNullOrEmpty(item.JanuaryEngineeringNum) || !string.IsNullOrEmpty(item.FebruaryEngineeringNum) ||
                        !string.IsNullOrEmpty(item.MarchEngineeringNum) || !string.IsNullOrEmpty(item.AprilEngineeringNum) ||
                        !string.IsNullOrEmpty(item.MayEngineeringNum) || !string.IsNullOrEmpty(item.JuneEngineeringNum) ||
                        !string.IsNullOrEmpty(item.JulyEngineeringNum) || !string.IsNullOrEmpty(item.AugustEngineeringNum) ||
                        !string.IsNullOrEmpty(item.SeptemberEngineeringNum) || !string.IsNullOrEmpty(item.OctoberEngineeringNum) ||
                        !string.IsNullOrEmpty(item.NovemberEngineeringNum) || !string.IsNullOrEmpty(item.DecemberEngineeringNum))
                    {
                        bool isMulUnit = false;
                        string yearPlanAmount = "0";
                        if (item.EngineeringUnit.Contains('/'))
                        {
                            yearPlanAmount = "0/0";
                            isMulUnit = true;
                        }
                        CountEngineeringNumForDetails(item.JanuaryEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.FebruaryEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.MarchEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.AprilEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.MayEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.JuneEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.JulyEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.AugustEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.SeptemberEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.OctoberEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.NovemberEngineeringNum, ref yearPlanAmount);
                        CountEngineeringNumForDetails(item.DecemberEngineeringNum, ref yearPlanAmount);

                        yearPlanDetailsView.YearPlanAmount = yearPlanAmount;
                        if (!string.IsNullOrEmpty(item.EngineeringNum))
                        {
                            if (isMulUnit)
                            {
                                string[] yearPlanAmountArr = yearPlanAmount.Split('/');
                                string[] totalAmountArr = item.EngineeringNum.Split('/');

                                yearPlanDetailsView.YearPlanProportion = Math.Round(Convert.ToDecimal(yearPlanAmountArr[0]) * 100 / Convert.ToDecimal(totalAmountArr[0]), 1).ToString() + "%";
                            }
                            else
                            {
                                yearPlanDetailsView.YearPlanProportion = Math.Round(Convert.ToDecimal(yearPlanAmount) * 100 / Convert.ToDecimal(item.EngineeringNum), 1).ToString() + "%";
                            }
                        }

                        yearPlanDetailsView.JanuaryProportion = CalculateMonthEngineeringProportionForDetails(item.JanuaryEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.FebruaryProportion = CalculateMonthEngineeringProportionForDetails(item.FebruaryEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.MarchProportion = CalculateMonthEngineeringProportionForDetails(item.MarchEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.AprilProportion = CalculateMonthEngineeringProportionForDetails(item.AprilEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.MayProportion = CalculateMonthEngineeringProportionForDetails(item.MayEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.JuneProportion = CalculateMonthEngineeringProportionForDetails(item.JuneEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.JulyProportion = CalculateMonthEngineeringProportionForDetails(item.JulyEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.AugustProportion = CalculateMonthEngineeringProportionForDetails(item.AugustEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.SeptemberProportion = CalculateMonthEngineeringProportionForDetails(item.SeptemberEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.OctoberProportion = CalculateMonthEngineeringProportionForDetails(item.OctoberEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.NovemberProportion = CalculateMonthEngineeringProportionForDetails(item.NovemberEngineeringNum, yearPlanAmount, isMulUnit);
                        yearPlanDetailsView.DecemberProportion = CalculateMonthEngineeringProportionForDetails(item.DecemberEngineeringNum, yearPlanAmount, isMulUnit);
                    }
                    lstYearPlanDetailsView.Add(yearPlanDetailsView);
                }
                #endregion

                #region MoneyUnit
                if (!string.IsNullOrEmpty(item.MoneyUnit))
                {
                    YearPlanDetailsView yearPlanDetailsView = new YearPlanDetailsView();
                    yearPlanDetailsView.ID = item.ID;
                    yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                    yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                    yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                    yearPlanDetailsView.Unit = item.MoneyUnit;
                    yearPlanDetailsView.TotalAmount = item.MoneyNum;

                    yearPlanDetailsView.JanuaryAmount = item.JanuaryMoneyNum;
                    yearPlanDetailsView.FebruaryAmount = item.FebruaryMoneyNum;
                    yearPlanDetailsView.MarchAmount = item.MarchMoneyNum;
                    yearPlanDetailsView.AprilAmount = item.AprilMoneyNum;
                    yearPlanDetailsView.MayAmount = item.MayMoneyNum;
                    yearPlanDetailsView.JuneAmount = item.JuneMoneyNum;
                    yearPlanDetailsView.JulyAmount = item.JulyMoneyNum;
                    yearPlanDetailsView.AugustAmount = item.AugustMoneyNum;
                    yearPlanDetailsView.SeptemberAmount = item.SeptemberMoneyNum;
                    yearPlanDetailsView.OctoberAmount = item.OctoberMoneyNum;
                    yearPlanDetailsView.NovemberAmount = item.NovemberMoneyNum;
                    yearPlanDetailsView.DecemberAmount = item.DecemberMoneyNum;

                    if (!string.IsNullOrEmpty(item.JanuaryMoneyNum) || !string.IsNullOrEmpty(item.FebruaryMoneyNum) ||
                        !string.IsNullOrEmpty(item.MarchMoneyNum) || !string.IsNullOrEmpty(item.AprilMoneyNum) ||
                        !string.IsNullOrEmpty(item.MayMoneyNum) || !string.IsNullOrEmpty(item.JuneMoneyNum) ||
                        !string.IsNullOrEmpty(item.JulyMoneyNum) || !string.IsNullOrEmpty(item.AugustMoneyNum) ||
                        !string.IsNullOrEmpty(item.SeptemberMoneyNum) || !string.IsNullOrEmpty(item.OctoberMoneyNum) ||
                        !string.IsNullOrEmpty(item.NovemberMoneyNum) || !string.IsNullOrEmpty(item.DecemberMoneyNum))
                    {
                        decimal yearPlanAmount = 0;
                        CountMonthMoneyNumForDetails(item.JanuaryMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.FebruaryMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.MarchMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.AprilMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.MayMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.JuneMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.JulyMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.AugustMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.SeptemberMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.OctoberMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.NovemberMoneyNum, ref yearPlanAmount);
                        CountMonthMoneyNumForDetails(item.DecemberMoneyNum, ref yearPlanAmount);
                        yearPlanDetailsView.YearPlanAmount = yearPlanAmount.ToString();
                        if (!string.IsNullOrEmpty(item.MoneyNum))
                        {
                            yearPlanDetailsView.YearPlanProportion = Math.Round(yearPlanAmount * 100 / Convert.ToDecimal(item.MoneyNum), 1).ToString() + "%";
                        }

                        yearPlanDetailsView.JanuaryProportion = CalculateMonthMoneyProportionForDetail(item.JanuaryMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.FebruaryProportion = CalculateMonthMoneyProportionForDetail(item.FebruaryMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.MarchProportion = CalculateMonthMoneyProportionForDetail(item.MarchMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.AprilProportion = CalculateMonthMoneyProportionForDetail(item.AprilMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.MayProportion = CalculateMonthMoneyProportionForDetail(item.MayMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.JuneProportion = CalculateMonthMoneyProportionForDetail(item.JuneMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.JulyProportion = CalculateMonthMoneyProportionForDetail(item.JulyMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.AugustProportion = CalculateMonthMoneyProportionForDetail(item.AugustMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.SeptemberProportion = CalculateMonthMoneyProportionForDetail(item.SeptemberMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.OctoberProportion = CalculateMonthMoneyProportionForDetail(item.OctoberMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.NovemberProportion = CalculateMonthMoneyProportionForDetail(item.NovemberMoneyNum, yearPlanAmount);
                        yearPlanDetailsView.DecemberProportion = CalculateMonthMoneyProportionForDetail(item.DecemberMoneyNum, yearPlanAmount);
                    }
                    lstYearPlanDetailsView.Add(yearPlanDetailsView);
                }
                #endregion
            }
            return lstYearPlanDetailsView;
        }

        //非申请人主数据列表
        public List<YearPlanView> GetYearPlanListForPreview(Guid projectID, string contractType, List<Guid> lstContractID)
        {
            List<YearPlanView> lstYearPlanView = new List<YearPlanView>();
            decimal totalMoney = 0;

            #region 统计总金额和各个月份的金额
            foreach (Guid contractID in lstContractID)
            {
                //获取指定标段的总金额
                string totalMoneyForContract = GetTotalReviseMoney(projectID, contractType, contractID);
                if (!string.IsNullOrEmpty(totalMoneyForContract))
                {
                    totalMoney += Convert.ToDecimal(totalMoneyForContract);
                }

                //获取年度计划数据
                var queryData = from yp in YearPlanRepository.Entities
                                where yp.ProjectID == projectID && yp.ContractType == contractType && yp.ContractID == contractID
                                select yp;
                foreach (var item in queryData)
                {
                    YearPlanRevise yearPlanRevise = YearPlanReviseRepository.Entities.Where(y => y.YearPlanID == item.ID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
                    if (yearPlanRevise != null)
                    {
                        YearPlanView yearPlanView = lstYearPlanView.SingleOrDefault(y => y.StatisticalCycle == yearPlanRevise.StatisticalCycle);
                        if (yearPlanView == null)
                        {
                            yearPlanView = new YearPlanView();
                            yearPlanView.ID = GuidHelper.NewGuid();
                            yearPlanView.StatisticalCycle = yearPlanRevise.StatisticalCycle;
                            yearPlanView.Unit = yearPlanRevise.Unit;
                            yearPlanView.JanuaryMoneyNum = "0";
                            yearPlanView.FebruaryMoneyNum = "0";
                            yearPlanView.MarchMoneyNum = "0";
                            yearPlanView.AprilMoneyNum = "0";
                            yearPlanView.MayMoneyNum = "0";
                            yearPlanView.JuneMoneyNum = "0";
                            yearPlanView.JulyMoneyNum = "0";
                            yearPlanView.AugustMoneyNum = "0";
                            yearPlanView.SeptemberMoneyNum = "0";
                            yearPlanView.OctoberMoneyNum = "0";
                            yearPlanView.NovemberMoneyNum = "0";
                            yearPlanView.DecemberMoneyNum = "0";
                            lstYearPlanView.Add(yearPlanView);
                        }

                        decimal januaryMoneyNum = 0;
                        decimal februaryMoneyNum = 0;
                        decimal marchMoneyNum = 0;
                        decimal aprilMoneyNum = 0;
                        decimal mayMoneyNum = 0;
                        decimal juneMoneyNum = 0;
                        decimal julyMoneyNum = 0;
                        decimal augustMoneyNum = 0;
                        decimal septemberMoneyNum = 0;
                        decimal octoberMoneyNum = 0;
                        decimal novemberMoneyNum = 0;
                        decimal decemberMoneyNum = 0;
                        var subQueryData = YearPlanReviseDetailsRepository.Entities.Where(y => y.YearPlanReviseID == yearPlanRevise.ID);
                        foreach (var detailItem in subQueryData)
                        {
                            StatisticsItemMaintenance statisticsItemMaintenance = StatisticsItemMaintenanceRepository.Entities.Single(s => s.ID == detailItem.StatisticsItemID);
                            if (statisticsItemMaintenance != null)
                            {
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JanuaryMoneyNum, ref januaryMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.FebruaryMoneyNum, ref februaryMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.MarchMoneyNum, ref marchMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.AprilMoneyNum, ref aprilMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.MayMoneyNum, ref mayMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JuneMoneyNum, ref juneMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.JulyMoneyNum, ref julyMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.AugustMoneyNum, ref augustMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.SeptemberMoneyNum, ref septemberMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.OctoberMoneyNum, ref octoberMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.NovemberMoneyNum, ref novemberMoneyNum);
                                CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, detailItem.DecemberMoneyNum, ref decemberMoneyNum);
                            }
                        }

                        yearPlanView.JanuaryMoneyNum = (Convert.ToDecimal(yearPlanView.JanuaryMoneyNum) + januaryMoneyNum).ToString();
                        yearPlanView.FebruaryMoneyNum = (Convert.ToDecimal(yearPlanView.FebruaryMoneyNum) + februaryMoneyNum).ToString();
                        yearPlanView.MarchMoneyNum = (Convert.ToDecimal(yearPlanView.MarchMoneyNum) + marchMoneyNum).ToString();
                        yearPlanView.AprilMoneyNum = (Convert.ToDecimal(yearPlanView.AprilMoneyNum) + aprilMoneyNum).ToString();
                        yearPlanView.MayMoneyNum = (Convert.ToDecimal(yearPlanView.MayMoneyNum) + mayMoneyNum).ToString();
                        yearPlanView.JuneMoneyNum = (Convert.ToDecimal(yearPlanView.JuneMoneyNum) + juneMoneyNum).ToString();
                        yearPlanView.JulyMoneyNum = (Convert.ToDecimal(yearPlanView.JulyMoneyNum) + julyMoneyNum).ToString();
                        yearPlanView.AugustMoneyNum = (Convert.ToDecimal(yearPlanView.AugustMoneyNum) + augustMoneyNum).ToString();
                        yearPlanView.SeptemberMoneyNum = (Convert.ToDecimal(yearPlanView.SeptemberMoneyNum) + septemberMoneyNum).ToString();
                        yearPlanView.OctoberMoneyNum = (Convert.ToDecimal(yearPlanView.OctoberMoneyNum) + octoberMoneyNum).ToString();
                        yearPlanView.NovemberMoneyNum = (Convert.ToDecimal(yearPlanView.NovemberMoneyNum) + novemberMoneyNum).ToString();
                        yearPlanView.DecemberMoneyNum = (Convert.ToDecimal(yearPlanView.DecemberMoneyNum) + decemberMoneyNum).ToString();
                    }
                }
            }
            #endregion

            if (lstYearPlanView.Count > 0)
            {
                foreach (YearPlanView yearPlanView in lstYearPlanView)
                {
                    yearPlanView.StatisticalCycle = yearPlanView.StatisticalCycle + "年";
                    yearPlanView.TotalMoney = totalMoney == 0 ? string.Empty : totalMoney.ToString();
                    decimal yearPlanMoney = Convert.ToDecimal(yearPlanView.JanuaryMoneyNum) + Convert.ToDecimal(yearPlanView.FebruaryMoneyNum) +
                                            Convert.ToDecimal(yearPlanView.MarchMoneyNum) + Convert.ToDecimal(yearPlanView.AprilMoneyNum) +
                                            Convert.ToDecimal(yearPlanView.MayMoneyNum) + Convert.ToDecimal(yearPlanView.JuneMoneyNum) +
                                            Convert.ToDecimal(yearPlanView.JulyMoneyNum) + Convert.ToDecimal(yearPlanView.AugustMoneyNum) +
                                            Convert.ToDecimal(yearPlanView.SeptemberMoneyNum) + Convert.ToDecimal(yearPlanView.OctoberMoneyNum) +
                                            Convert.ToDecimal(yearPlanView.NovemberMoneyNum) + Convert.ToDecimal(yearPlanView.DecemberMoneyNum);

                    yearPlanView.JanuaryMoneyNum = yearPlanView.JanuaryMoneyNum == "0" ? string.Empty : yearPlanView.JanuaryMoneyNum;
                    yearPlanView.FebruaryMoneyNum = yearPlanView.FebruaryMoneyNum == "0" ? string.Empty : yearPlanView.FebruaryMoneyNum;
                    yearPlanView.MarchMoneyNum = yearPlanView.MarchMoneyNum == "0" ? string.Empty : yearPlanView.MarchMoneyNum;
                    yearPlanView.AprilMoneyNum = yearPlanView.AprilMoneyNum == "0" ? string.Empty : yearPlanView.AprilMoneyNum;
                    yearPlanView.MayMoneyNum = yearPlanView.MayMoneyNum == "0" ? string.Empty : yearPlanView.MayMoneyNum;
                    yearPlanView.JuneMoneyNum = yearPlanView.JuneMoneyNum == "0" ? string.Empty : yearPlanView.JuneMoneyNum;
                    yearPlanView.JulyMoneyNum = yearPlanView.JulyMoneyNum == "0" ? string.Empty : yearPlanView.JulyMoneyNum;
                    yearPlanView.AugustMoneyNum = yearPlanView.AugustMoneyNum == "0" ? string.Empty : yearPlanView.AugustMoneyNum;
                    yearPlanView.SeptemberMoneyNum = yearPlanView.SeptemberMoneyNum == "0" ? string.Empty : yearPlanView.SeptemberMoneyNum;
                    yearPlanView.OctoberMoneyNum = yearPlanView.OctoberMoneyNum == "0" ? string.Empty : yearPlanView.OctoberMoneyNum;
                    yearPlanView.NovemberMoneyNum = yearPlanView.NovemberMoneyNum == "0" ? string.Empty : yearPlanView.NovemberMoneyNum;
                    yearPlanView.DecemberMoneyNum = yearPlanView.DecemberMoneyNum == "0" ? string.Empty : yearPlanView.DecemberMoneyNum;
                    yearPlanView.YearPlanMoney = yearPlanMoney == 0 ? string.Empty : yearPlanMoney.ToString();

                    yearPlanView.YearPlanProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.TotalMoney, yearPlanView.YearPlanMoney);
                    yearPlanView.JanuaryProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.JanuaryMoneyNum);
                    yearPlanView.FebruaryProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.FebruaryMoneyNum);
                    yearPlanView.MarchProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.MarchMoneyNum);
                    yearPlanView.AprilProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.AprilMoneyNum);
                    yearPlanView.MayProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.MayMoneyNum);
                    yearPlanView.JuneProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.JuneMoneyNum);
                    yearPlanView.JulyProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.JulyMoneyNum);
                    yearPlanView.AugustProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.AugustMoneyNum);
                    yearPlanView.SeptemberProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.SeptemberMoneyNum);
                    yearPlanView.OctoberProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.OctoberMoneyNum);
                    yearPlanView.NovemberProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.NovemberMoneyNum);
                    yearPlanView.DecemberProportion = CalculateMonthMoneyProportionForPreview(yearPlanView.YearPlanMoney, yearPlanView.DecemberMoneyNum);
                }
            }
            else
            {
                if (totalMoney > 0)
                {
                    lstYearPlanView.Add(new YearPlanView() { TotalMoney = totalMoney.ToString() });
                }
            }
            return lstYearPlanView;
        }

        //非申请人明细数据列表
        public List<YearPlanDetailsView> GetYearPlanDetailListForPreview(Guid projectID, string contractType, List<Guid> lstContractID, string statisticalCycle)
        {
            List<YearPlanDetailsView> lstYearPlanDetailsView = new List<YearPlanDetailsView>();
            foreach (Guid contractID in lstContractID)
            {
                //获取总量维护修订ID
                Guid reviseID = GetTotalReviseID(projectID, contractType, contractID);

                //获取总量维护修订明细
                var queryTotalReviseDetails = from td in TotalReviseDetailsRepository.Entities
                                              where td.TotalReviseID == reviseID
                                              select td;

                //先获取年度计划，然后获取年度计划修订
                Guid yearPlanID = GuidHelper.NewGuid();
                Guid yearPlanReviseID = GuidHelper.NewGuid();
                YearPlan yearPlan = YearPlanRepository.Entities.SingleOrDefault(yp => yp.ProjectID == projectID && yp.ContractType == contractType && yp.ContractID == contractID && yp.StatisticalCycle == statisticalCycle);
                if (yearPlan != null)
                {
                    yearPlanID = yearPlan.ID;
                }
                YearPlanRevise yearPlanRevise = YearPlanReviseRepository.Entities.Where(y => y.YearPlanID == yearPlanID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
                if (yearPlanRevise != null)
                {
                    yearPlanReviseID = yearPlanRevise.ID;
                }
                //获取年度计划修订明细
                var queryYearPlanReviseDetails = from y in YearPlanReviseDetailsRepository.Entities
                                                 where y.YearPlanReviseID == yearPlanReviseID
                                                 select y;

                if (queryTotalReviseDetails.Count() > 0 || queryYearPlanReviseDetails.Count() > 0)
                {
                    #region 连接查询获取基础数据
                    var queryData = from s in StatisticsItemMaintenanceRepository.Entities
                                    join td in queryTotalReviseDetails
                                    on s.ID equals td.StatisticsItemID into joinedEmpTD
                                    from tempTD in joinedEmpTD.DefaultIfEmpty()
                                    join yd in queryYearPlanReviseDetails
                                    on s.ID equals yd.StatisticsItemID into joinedEmpYD
                                    from tempYD in joinedEmpYD.DefaultIfEmpty()
                                    where s.IsParent == false && s.ProjectID == projectID && s.ContractType == contractType
                                    orderby s.OrderNo
                                    select new
                                    {
                                        StatisticsItemID = s.ID,
                                        s.StatisticsItemName,
                                        s.PID,
                                        s.EngineeringUnit,
                                        s.MoneyUnit,
                                        tempTD.EngineeringNum,
                                        tempTD.MoneyNum,
                                        ID = tempYD == null ? Guid.NewGuid() : tempYD.ID,
                                        tempYD.JanuaryEngineeringNum,
                                        tempYD.JanuaryMoneyNum,
                                        tempYD.FebruaryEngineeringNum,
                                        tempYD.FebruaryMoneyNum,
                                        tempYD.MarchEngineeringNum,
                                        tempYD.MarchMoneyNum,
                                        tempYD.AprilEngineeringNum,
                                        tempYD.AprilMoneyNum,
                                        tempYD.MayEngineeringNum,
                                        tempYD.MayMoneyNum,
                                        tempYD.JuneEngineeringNum,
                                        tempYD.JuneMoneyNum,
                                        tempYD.JulyEngineeringNum,
                                        tempYD.JulyMoneyNum,
                                        tempYD.AugustEngineeringNum,
                                        tempYD.AugustMoneyNum,
                                        tempYD.SeptemberEngineeringNum,
                                        tempYD.SeptemberMoneyNum,
                                        tempYD.OctoberEngineeringNum,
                                        tempYD.OctoberMoneyNum,
                                        tempYD.NovemberEngineeringNum,
                                        tempYD.NovemberMoneyNum,
                                        tempYD.DecemberEngineeringNum,
                                        tempYD.DecemberMoneyNum
                                    };
                    #endregion

                    foreach (var item in queryData)
                    {
                        string parentStatisticsItemName = item.StatisticsItemName;
                        if (item.PID != null)
                        {
                            parentStatisticsItemName = GetParentStatisticsItemName(item.PID);
                        }

                        #region EngineeringUnit
                        if (!string.IsNullOrEmpty(item.EngineeringUnit))
                        {
                            YearPlanDetailsView yearPlanDetailsView = lstYearPlanDetailsView.SingleOrDefault(yd => yd.StatisticsItemID == item.StatisticsItemID && yd.IsBelongToMoneyNum == "0");
                            if (yearPlanDetailsView == null)
                            {
                                yearPlanDetailsView = new YearPlanDetailsView();
                                yearPlanDetailsView.ID = item.ID;
                                yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                                yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                                yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                                yearPlanDetailsView.Unit = item.EngineeringUnit;
                                yearPlanDetailsView.IsBelongToMoneyNum = "0";
                                lstYearPlanDetailsView.Add(yearPlanDetailsView);
                            }

                            yearPlanDetailsView.TotalAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.TotalAmount, item.EngineeringNum);
                            yearPlanDetailsView.JanuaryAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JanuaryAmount, item.JanuaryEngineeringNum);
                            yearPlanDetailsView.FebruaryAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.FebruaryAmount, item.FebruaryEngineeringNum);
                            yearPlanDetailsView.MarchAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.MarchAmount, item.MarchEngineeringNum);
                            yearPlanDetailsView.AprilAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.AprilAmount, item.AprilEngineeringNum);
                            yearPlanDetailsView.MayAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.MayAmount, item.MayEngineeringNum);
                            yearPlanDetailsView.JuneAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JuneAmount, item.JuneEngineeringNum);
                            yearPlanDetailsView.JulyAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JulyAmount, item.JulyEngineeringNum);
                            yearPlanDetailsView.AugustAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.AugustAmount, item.AugustEngineeringNum);
                            yearPlanDetailsView.SeptemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.SeptemberAmount, item.SeptemberEngineeringNum);
                            yearPlanDetailsView.OctoberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.OctoberAmount, item.OctoberEngineeringNum);
                            yearPlanDetailsView.NovemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.NovemberAmount, item.NovemberEngineeringNum);
                            yearPlanDetailsView.DecemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.DecemberAmount, item.DecemberEngineeringNum);
                        }
                        #endregion

                        #region MoneyUnit
                        if (!string.IsNullOrEmpty(item.MoneyUnit))
                        {
                            YearPlanDetailsView yearPlanDetailsView = lstYearPlanDetailsView.SingleOrDefault(yd => yd.StatisticsItemID == item.StatisticsItemID && yd.IsBelongToMoneyNum == "1");
                            if (yearPlanDetailsView == null)
                            {
                                yearPlanDetailsView = new YearPlanDetailsView();
                                yearPlanDetailsView.ID = item.ID;
                                yearPlanDetailsView.StatisticsItemID = item.StatisticsItemID;
                                yearPlanDetailsView.StatisticsItemName = item.StatisticsItemName;
                                yearPlanDetailsView.ParentStatisticsItemName = parentStatisticsItemName;
                                yearPlanDetailsView.Unit = item.MoneyUnit;
                                yearPlanDetailsView.IsBelongToMoneyNum = "1";
                                lstYearPlanDetailsView.Add(yearPlanDetailsView);
                            }

                            yearPlanDetailsView.TotalAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.TotalAmount, item.MoneyNum);
                            yearPlanDetailsView.JanuaryAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JanuaryAmount, item.JanuaryMoneyNum);
                            yearPlanDetailsView.FebruaryAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.FebruaryAmount, item.FebruaryMoneyNum);
                            yearPlanDetailsView.MarchAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.MarchAmount, item.MarchMoneyNum);
                            yearPlanDetailsView.AprilAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.AprilAmount, item.AprilMoneyNum);
                            yearPlanDetailsView.MayAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.MayAmount, item.MayMoneyNum);
                            yearPlanDetailsView.JuneAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JuneAmount, item.JuneMoneyNum);
                            yearPlanDetailsView.JulyAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.JulyAmount, item.JulyMoneyNum);
                            yearPlanDetailsView.AugustAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.AugustAmount, item.AugustMoneyNum);
                            yearPlanDetailsView.SeptemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.SeptemberAmount, item.SeptemberMoneyNum);
                            yearPlanDetailsView.OctoberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.OctoberAmount, item.OctoberMoneyNum);
                            yearPlanDetailsView.NovemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.NovemberAmount, item.NovemberMoneyNum);
                            yearPlanDetailsView.DecemberAmount = TotalEngineeringOrMoneyNumForPreviewDetails(yearPlanDetailsView.DecemberAmount, item.DecemberMoneyNum);
                        }
                        #endregion
                    }
                }
            }

            #region 处理占比
            foreach (YearPlanDetailsView item in lstYearPlanDetailsView)
            {
                if (item.IsBelongToMoneyNum == "0")
                {
                    bool isMulUnit = false;
                    string yearPlanAmount = "0";
                    if (item.Unit.Contains('/'))
                    {
                        yearPlanAmount = "0/0";
                        isMulUnit = true;
                    }
                    CountEngineeringNumForDetails(item.JanuaryAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.FebruaryAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.MarchAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.AprilAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.MayAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.JuneAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.JulyAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.AugustAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.SeptemberAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.OctoberAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.NovemberAmount, ref yearPlanAmount);
                    CountEngineeringNumForDetails(item.DecemberAmount, ref yearPlanAmount);

                    if (yearPlanAmount != "0" && yearPlanAmount != "0/0")
                    {
                        item.YearPlanAmount = yearPlanAmount;
                        if (!string.IsNullOrEmpty(item.TotalAmount) && item.TotalAmount != "0" && item.TotalAmount != "0/0")
                        {
                            item.YearPlanProportion = CalculateMonthEngineeringProportionForDetails(yearPlanAmount, item.TotalAmount, isMulUnit);
                        }
                        item.JanuaryProportion = CalculateMonthEngineeringProportionForDetails(item.JanuaryAmount, yearPlanAmount, isMulUnit);
                        item.FebruaryProportion = CalculateMonthEngineeringProportionForDetails(item.FebruaryAmount, yearPlanAmount, isMulUnit);
                        item.MarchProportion = CalculateMonthEngineeringProportionForDetails(item.MarchAmount, yearPlanAmount, isMulUnit);
                        item.AprilProportion = CalculateMonthEngineeringProportionForDetails(item.AprilAmount, yearPlanAmount, isMulUnit);
                        item.MayProportion = CalculateMonthEngineeringProportionForDetails(item.MayAmount, yearPlanAmount, isMulUnit);
                        item.JuneProportion = CalculateMonthEngineeringProportionForDetails(item.JuneAmount, yearPlanAmount, isMulUnit);
                        item.JulyProportion = CalculateMonthEngineeringProportionForDetails(item.JulyAmount, yearPlanAmount, isMulUnit);
                        item.AugustProportion = CalculateMonthEngineeringProportionForDetails(item.AugustAmount, yearPlanAmount, isMulUnit);
                        item.SeptemberProportion = CalculateMonthEngineeringProportionForDetails(item.SeptemberAmount, yearPlanAmount, isMulUnit);
                        item.OctoberProportion = CalculateMonthEngineeringProportionForDetails(item.OctoberAmount, yearPlanAmount, isMulUnit);
                        item.NovemberProportion = CalculateMonthEngineeringProportionForDetails(item.NovemberAmount, yearPlanAmount, isMulUnit);
                        item.DecemberProportion = CalculateMonthEngineeringProportionForDetails(item.DecemberAmount, yearPlanAmount, isMulUnit);
                    }
                }
                else
                {
                    decimal yearPlanAmount = 0;
                    CountMonthMoneyNumForDetails(item.JanuaryAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.FebruaryAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.MarchAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.AprilAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.MayAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.JuneAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.JulyAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.AugustAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.SeptemberAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.OctoberAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.NovemberAmount, ref yearPlanAmount);
                    CountMonthMoneyNumForDetails(item.DecemberAmount, ref yearPlanAmount);
                    item.YearPlanAmount = yearPlanAmount == 0 ? string.Empty : yearPlanAmount.ToString();
                    if (yearPlanAmount != 0)
                    {
                        if (!string.IsNullOrEmpty(item.TotalAmount) && item.TotalAmount != "0")
                        {
                            item.YearPlanProportion = Math.Round(yearPlanAmount * 100 / Convert.ToDecimal(item.TotalAmount), 1).ToString() + "%";
                        }
                        item.JanuaryProportion = CalculateMonthMoneyProportionForDetail(item.JanuaryAmount, yearPlanAmount);
                        item.FebruaryProportion = CalculateMonthMoneyProportionForDetail(item.FebruaryAmount, yearPlanAmount);
                        item.MarchProportion = CalculateMonthMoneyProportionForDetail(item.MarchAmount, yearPlanAmount);
                        item.AprilProportion = CalculateMonthMoneyProportionForDetail(item.AprilAmount, yearPlanAmount);
                        item.MayProportion = CalculateMonthMoneyProportionForDetail(item.MayAmount, yearPlanAmount);
                        item.JuneProportion = CalculateMonthMoneyProportionForDetail(item.JuneAmount, yearPlanAmount);
                        item.JulyProportion = CalculateMonthMoneyProportionForDetail(item.JulyAmount, yearPlanAmount);
                        item.AugustProportion = CalculateMonthMoneyProportionForDetail(item.AugustAmount, yearPlanAmount);
                        item.SeptemberProportion = CalculateMonthMoneyProportionForDetail(item.SeptemberAmount, yearPlanAmount);
                        item.OctoberProportion = CalculateMonthMoneyProportionForDetail(item.OctoberAmount, yearPlanAmount);
                        item.NovemberProportion = CalculateMonthMoneyProportionForDetail(item.NovemberAmount, yearPlanAmount);
                        item.DecemberProportion = CalculateMonthMoneyProportionForDetail(item.DecemberAmount, yearPlanAmount);
                    }
                }
            }
            #endregion

            return lstYearPlanDetailsView;
        }
        #endregion

        public YearPlanView GetYearPlanByID(Guid id)
        {
            YearPlan yearPlan = YearPlanRepository.Entities.SingleOrDefault(t => t.ID == id);
            YearPlanView yearPlanView = null;
            if (yearPlan != null)
            {
                yearPlanView = new YearPlanView();
                yearPlanView.ID = yearPlan.ID;
                yearPlanView.FlowCode = yearPlan.FlowCode;
                yearPlanView.ProjectID = yearPlan.ProjectID;
                yearPlanView.ContractType = yearPlan.ContractType;
                yearPlanView.ContractID = yearPlan.ContractID;
                yearPlanView.StatisticalCycle = yearPlan.StatisticalCycle;
                yearPlanView.Unit = yearPlan.Unit;
                yearPlanView.RequestDate = yearPlan.RequestDate;
                yearPlanView.RequestNodeCode = yearPlan.RequestNodeCode;
                yearPlanView.RequestUserDepartment = yearPlan.RequestUserDepartment;
                yearPlanView.RequestPerson = yearPlan.RequestPerson;
                yearPlanView.HandleState = yearPlan.HandleState;
                yearPlanView.AssociatedNodeCode = yearPlan.AssociatedNodeCode;
                yearPlanView.LastUpdateUserDepartment = yearPlan.LastUpdateUserDepartment;
                yearPlanView.LastUpdateUser = yearPlan.LastUpdateUser;
                yearPlanView.LastUpdateTime = yearPlan.LastUpdateTime;
                yearPlanView.SaveState = yearPlan.SaveState;
            }
            return yearPlanView;
        }

        #region 单据保存
        public void SaveYearPlan(YearPlanView yearPlanView, List<YearPlanDetailsView> saveList, bool isUpdateDetails = true)
        {
            YearPlan record = YearPlanRepository.Entities.FirstOrDefault(a => a.ID == yearPlanView.ID);
            if (record != null)
            {
                UpdateYearPlan(record, yearPlanView);
            }
            else
            {
                InsertYearPlan(yearPlanView);
            }

            if (isUpdateDetails)
            {
                DeleteYearPlanDetails(yearPlanView.ID);
                foreach (YearPlanDetailsView yearPlanDetailsView in saveList)
                {
                    InsertYearPlanDetails(yearPlanDetailsView);
                }
            }
        }

        private void InsertYearPlan(YearPlanView yearPlanView)
        {
            YearPlan record = new YearPlan()
            {
                ID = yearPlanView.ID,
                FlowCode = yearPlanView.FlowCode,
                ProjectID = yearPlanView.ProjectID,
                ContractType = yearPlanView.ContractType,
                ContractID = yearPlanView.ContractID,
                StatisticalCycle = yearPlanView.StatisticalCycle,
                Unit = yearPlanView.Unit,
                RequestDate = yearPlanView.RequestDate,
                RequestNodeCode = yearPlanView.RequestNodeCode,
                RequestUserDepartment = yearPlanView.RequestUserDepartment,
                RequestPerson = yearPlanView.RequestPerson,
                HandleState = yearPlanView.HandleState,
                AssociatedNodeCode = yearPlanView.AssociatedNodeCode,
                LastUpdateUserDepartment = yearPlanView.LastUpdateUserDepartment,
                LastUpdateUser = yearPlanView.LastUpdateUser,
                LastUpdateTime = yearPlanView.LastUpdateTime,
                SaveState = yearPlanView.SaveState
            };
            YearPlanRepository.Insert(record);
        }

        private void UpdateYearPlan(YearPlan record, YearPlanView yearPlanView)
        {
            record.StatisticalCycle = yearPlanView.StatisticalCycle;
            record.HandleState = yearPlanView.HandleState;
            record.AssociatedNodeCode = yearPlanView.AssociatedNodeCode;
            record.LastUpdateUserDepartment = yearPlanView.LastUpdateUserDepartment;
            record.LastUpdateUser = yearPlanView.LastUpdateUser;
            record.LastUpdateTime = yearPlanView.LastUpdateTime;
            record.SaveState = yearPlanView.SaveState;
            YearPlanRepository.Update(record);
        }

        private void DeleteYearPlanDetails(Guid yeatPlanID)
        {
            List<YearPlanDetails> lstYearPlanDetails = YearPlanDetailsRepository.Entities.Where(a => a.YearPlanID == yeatPlanID).ToList();
            foreach (YearPlanDetails yearPlanDetails in lstYearPlanDetails)
            {
                YearPlanDetailsRepository.Delete(yearPlanDetails.ID);
            }
        }

        private void InsertYearPlanDetails(YearPlanDetailsView yearPlanDetailsView)
        {
            YearPlanDetails record = new YearPlanDetails()
            {
                ID = yearPlanDetailsView.ID,
                YearPlanID = yearPlanDetailsView.YearPlanID,
                StatisticsItemID = yearPlanDetailsView.StatisticsItemID,
                JanuaryEngineeringNum = yearPlanDetailsView.JanuaryEngineeringNum,
                JanuaryMoneyNum = yearPlanDetailsView.JanuaryMoneyNum,
                FebruaryEngineeringNum = yearPlanDetailsView.FebruaryEngineeringNum,
                FebruaryMoneyNum = yearPlanDetailsView.FebruaryMoneyNum,
                MarchEngineeringNum = yearPlanDetailsView.MarchEngineeringNum,
                MarchMoneyNum = yearPlanDetailsView.MarchMoneyNum,
                AprilEngineeringNum = yearPlanDetailsView.AprilEngineeringNum,
                AprilMoneyNum = yearPlanDetailsView.AprilMoneyNum,
                MayEngineeringNum = yearPlanDetailsView.MayEngineeringNum,
                MayMoneyNum = yearPlanDetailsView.MayMoneyNum,
                JuneEngineeringNum = yearPlanDetailsView.JuneEngineeringNum,
                JuneMoneyNum = yearPlanDetailsView.JuneMoneyNum,
                JulyEngineeringNum = yearPlanDetailsView.JulyEngineeringNum,
                JulyMoneyNum = yearPlanDetailsView.JulyMoneyNum,
                AugustEngineeringNum = yearPlanDetailsView.AugustEngineeringNum,
                AugustMoneyNum = yearPlanDetailsView.AugustMoneyNum,
                SeptemberEngineeringNum = yearPlanDetailsView.SeptemberEngineeringNum,
                SeptemberMoneyNum = yearPlanDetailsView.SeptemberMoneyNum,
                OctoberEngineeringNum = yearPlanDetailsView.OctoberEngineeringNum,
                OctoberMoneyNum = yearPlanDetailsView.OctoberMoneyNum,
                NovemberEngineeringNum = yearPlanDetailsView.NovemberEngineeringNum,
                NovemberMoneyNum = yearPlanDetailsView.NovemberMoneyNum,
                DecemberEngineeringNum = yearPlanDetailsView.DecemberEngineeringNum,
                DecemberMoneyNum = yearPlanDetailsView.DecemberMoneyNum
            };
            YearPlanDetailsRepository.Insert(record);
        }
        #endregion

        public OperationResult Revise(Guid yearPlanID, Guid yearPlanReviseID)
        {
            try
            {
                YearPlan record = YearPlanRepository.Entities.SingleOrDefault(t => t.ID == yearPlanID);
                YearPlanRevise recordRevise = YearPlanReviseRepository.Entities.SingleOrDefault(t => t.ID == yearPlanReviseID);
                if (record != null && recordRevise != null)
                {
                    record.HandleState = "0";
                    record.AssociatedNodeCode = record.RequestNodeCode;
                    record.LastUpdateUserDepartment = record.RequestUserDepartment;
                    record.LastUpdateUser = record.RequestPerson;
                    YearPlanRepository.Update(record);

                    DeleteYearPlanDetails(yearPlanID);

                    List<YearPlanReviseDetails> lstYearPlanReviseDetails = YearPlanReviseDetailsRepository.Entities.Where(a => a.YearPlanReviseID == yearPlanReviseID).ToList();
                    foreach (YearPlanReviseDetails yearPlanReviseDetails in lstYearPlanReviseDetails)
                    {
                        YearPlanDetails yearPlanDetails = new YearPlanDetails();
                        yearPlanDetails.YearPlanID = record.ID;
                        yearPlanDetails.StatisticsItemID = yearPlanReviseDetails.StatisticsItemID;
                        yearPlanDetails.JanuaryEngineeringNum = yearPlanReviseDetails.JanuaryEngineeringNum;
                        yearPlanDetails.JanuaryMoneyNum = yearPlanReviseDetails.JanuaryMoneyNum;
                        yearPlanDetails.FebruaryEngineeringNum = yearPlanReviseDetails.FebruaryEngineeringNum;
                        yearPlanDetails.FebruaryMoneyNum = yearPlanReviseDetails.FebruaryMoneyNum;
                        yearPlanDetails.MarchEngineeringNum = yearPlanReviseDetails.MarchEngineeringNum;
                        yearPlanDetails.MarchMoneyNum = yearPlanReviseDetails.MarchMoneyNum;
                        yearPlanDetails.AprilEngineeringNum = yearPlanReviseDetails.AprilEngineeringNum;
                        yearPlanDetails.AprilMoneyNum = yearPlanReviseDetails.AprilMoneyNum;
                        yearPlanDetails.MayEngineeringNum = yearPlanReviseDetails.MayEngineeringNum;
                        yearPlanDetails.MayMoneyNum = yearPlanReviseDetails.MayMoneyNum;
                        yearPlanDetails.JuneEngineeringNum = yearPlanReviseDetails.JuneEngineeringNum;
                        yearPlanDetails.JuneMoneyNum = yearPlanReviseDetails.JuneMoneyNum;
                        yearPlanDetails.JulyEngineeringNum = yearPlanReviseDetails.JulyEngineeringNum;
                        yearPlanDetails.JulyMoneyNum = yearPlanReviseDetails.JulyMoneyNum;
                        yearPlanDetails.AugustEngineeringNum = yearPlanReviseDetails.AugustEngineeringNum;
                        yearPlanDetails.AugustMoneyNum = yearPlanReviseDetails.AugustMoneyNum;
                        yearPlanDetails.SeptemberEngineeringNum = yearPlanReviseDetails.SeptemberEngineeringNum;
                        yearPlanDetails.SeptemberMoneyNum = yearPlanReviseDetails.SeptemberMoneyNum;
                        yearPlanDetails.OctoberEngineeringNum = yearPlanReviseDetails.OctoberEngineeringNum;
                        yearPlanDetails.OctoberMoneyNum = yearPlanReviseDetails.OctoberMoneyNum;
                        yearPlanDetails.NovemberEngineeringNum = yearPlanReviseDetails.NovemberEngineeringNum;
                        yearPlanDetails.NovemberMoneyNum = yearPlanReviseDetails.NovemberMoneyNum;
                        yearPlanDetails.DecemberEngineeringNum = yearPlanReviseDetails.DecemberEngineeringNum;
                        yearPlanDetails.DecemberMoneyNum = yearPlanReviseDetails.DecemberMoneyNum;
                        YearPlanDetailsRepository.Insert(yearPlanDetails);
                    }



                    string sql = @"DELETE FROM BaklogTasks WHERE RecordID='" + record.ID + "';" +
                                  "DELETE FROM BaklogTaskTemps WHERE RecordID='" + record.ID + "';" +
                                  "DELETE FROM CompleteFlowNodes WHERE RecordID='" + record.ID + "';" +
                                  "DELETE FROM FlowGraphNodes WHERE RecordID='" + record.ID + "';" +
                                  "DELETE FROM FlowProcessMessages WHERE RecordID='" + record.ID + "';" +
                                  "DELETE FROM ProcessedTasks WHERE RecordID='" + record.ID + "';";
                    YearPlanRepository.ExeSqlCommon(sql);

                    BaklogTask baklogTask = new BaklogTask();
                    baklogTask.ID = GuidHelper.NewGuid();
                    baklogTask.RecordID = record.ID.ToString();
                    baklogTask.TaskType = record.FlowCode;
                    baklogTask.RequestDate = record.RequestDate;
                    baklogTask.CurrentFlowNodeCode = record.AssociatedNodeCode;
                    baklogTask.CurrentProcessPersonDepartment = record.LastUpdateUserDepartment;
                    baklogTask.CurrentProcessPerson = record.LastUpdateUser;
                    baklogTask.NodeLevel = 1;
                    BaklogTaskRepository.Insert(baklogTask);

                    return new OperationResult(OperationResultType.Success, "修订成功", record);
                }
                else
                {
                    return new OperationResult(OperationResultType.QueryNull, "未找到指定的记录");
                }
            }
            catch (Exception ex)
            {
                return new OperationResult(OperationResultType.Error, "删除失败:" + ex.Message);
            }
        }

        public OperationResult Delete(Guid yearPlanID)
        {
            try
            {
                YearPlan record = YearPlanRepository.Entities.SingleOrDefault(t => t.ID == yearPlanID);
                if (record == null)
                    return new OperationResult(OperationResultType.QueryNull, "未找到指定的记录");
                if (record != null)
                {
                    YearPlanRepository.Delete(record);
                }

                List<YearPlanRevise> lstYearPlanRevise = YearPlanReviseRepository.Entities.Where(t => t.YearPlanID == yearPlanID).ToList();
                foreach (YearPlanRevise yearPlanRevise in lstYearPlanRevise)
                {
                    List<YearPlanReviseDetails> lstYearPlanReviseDetails = YearPlanReviseDetailsRepository.Entities.Where(t => t.YearPlanReviseID == yearPlanRevise.ID).ToList();
                    foreach (YearPlanReviseDetails yearPlanReviseDetails in lstYearPlanReviseDetails)
                    {
                        YearPlanReviseDetailsRepository.Delete(yearPlanReviseDetails.ID);
                    }
                    YearPlanReviseRepository.Delete(yearPlanRevise.ID);
                }
                string sql = @"DELETE FROM YearPlanDetails WHERE YearPlanID='" + record.ID + "';" +
                              "DELETE FROM BaklogTasks WHERE RecordID='" + record.ID + "';" +
                              "DELETE FROM BaklogTaskTemps WHERE RecordID='" + record.ID + "';" +
                              "DELETE FROM CompleteFlowNodes WHERE RecordID='" + record.ID + "';" +
                              "DELETE FROM FlowGraphNodes WHERE RecordID='" + record.ID + "';" +
                              "DELETE FROM FlowProcessMessages WHERE RecordID='" + record.ID + "';" +
                              "DELETE FROM ProcessedTasks WHERE RecordID='" + record.ID + "';";
                YearPlanRepository.ExeSqlCommon(sql);
                return new OperationResult(OperationResultType.Success, "删除成功", record);
            }
            catch (Exception ex)
            {
                return new OperationResult(OperationResultType.Error, "删除失败:" + ex.Message);
            }
        }

        public void AddReviseData(Guid yearPlanID)
        {
            YearPlan yearPlan = YearPlanRepository.Entities.SingleOrDefault(t => t.ID == yearPlanID);
            if (yearPlan != null)
            {
                YearPlanRevise yearPlanRevise = new YearPlanRevise();
                decimal totalJanuaryMoneyNum = 0;
                decimal totalFebruaryMoneyNum = 0;
                decimal totalMarchMoneyNum = 0;
                decimal totalAprilMoneyNum = 0;
                decimal totalMayMoneyNum = 0;
                decimal totalJuneMoneyNum = 0;
                decimal totalJulyMoneyNum = 0;
                decimal totalAugustMoneyNum = 0;
                decimal totalSeptemberMoneyNum = 0;
                decimal totalOctoberMoneyNum = 0;
                decimal totalNovemberMoneyNum = 0;
                decimal totalDecemberMoneyNum = 0;
                List<YearPlanDetails> lstYearPlanDetail = YearPlanDetailsRepository.Entities.Where(td => td.YearPlanID == yearPlanID).ToList();
                foreach (YearPlanDetails yearPlanDetails in lstYearPlanDetail)
                {
                    StatisticsItemMaintenance statisticsItemMaintenance = StatisticsItemMaintenanceRepository.Entities.Single(s => s.ID == yearPlanDetails.StatisticsItemID);

                    //统计所有明细的MoneyNum
                    if (statisticsItemMaintenance != null && (!string.IsNullOrEmpty(yearPlanDetails.JanuaryMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.FebruaryMoneyNum) || !string.IsNullOrEmpty(yearPlanDetails.MarchMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.AprilMoneyNum) || !string.IsNullOrEmpty(yearPlanDetails.MayMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.JuneMoneyNum) || !string.IsNullOrEmpty(yearPlanDetails.JulyMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.AugustMoneyNum) || !string.IsNullOrEmpty(yearPlanDetails.SeptemberMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.OctoberMoneyNum) || !string.IsNullOrEmpty(yearPlanDetails.NovemberMoneyNum)
                        || !string.IsNullOrEmpty(yearPlanDetails.DecemberMoneyNum)))
                    {
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.JanuaryMoneyNum, ref totalJanuaryMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.FebruaryMoneyNum, ref totalFebruaryMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.MarchMoneyNum, ref totalMarchMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.AprilMoneyNum, ref totalAprilMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.MayMoneyNum, ref totalMayMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.JuneMoneyNum, ref totalJuneMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.JulyMoneyNum, ref totalJulyMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.AugustMoneyNum, ref totalAugustMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.SeptemberMoneyNum, ref totalSeptemberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.OctoberMoneyNum, ref totalOctoberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.NovemberMoneyNum, ref totalNovemberMoneyNum);
                        CountMonthMoneyNum(statisticsItemMaintenance.MoneyUnit, yearPlanDetails.DecemberMoneyNum, ref totalDecemberMoneyNum);
                    }

                    YearPlanReviseDetails yearPlanReviseDetails = new YearPlanReviseDetails();
                    yearPlanReviseDetails.YearPlanReviseID = yearPlanRevise.ID;
                    yearPlanReviseDetails.StatisticsItemID = yearPlanDetails.StatisticsItemID;
                    yearPlanReviseDetails.JanuaryEngineeringNum = yearPlanDetails.JanuaryEngineeringNum;
                    yearPlanReviseDetails.JanuaryMoneyNum = yearPlanDetails.JanuaryMoneyNum;
                    yearPlanReviseDetails.FebruaryEngineeringNum = yearPlanDetails.FebruaryEngineeringNum;
                    yearPlanReviseDetails.FebruaryMoneyNum = yearPlanDetails.FebruaryMoneyNum;
                    yearPlanReviseDetails.MarchEngineeringNum = yearPlanDetails.MarchEngineeringNum;
                    yearPlanReviseDetails.MarchMoneyNum = yearPlanDetails.MarchMoneyNum;
                    yearPlanReviseDetails.AprilEngineeringNum = yearPlanDetails.AprilEngineeringNum;
                    yearPlanReviseDetails.AprilMoneyNum = yearPlanDetails.AprilMoneyNum;
                    yearPlanReviseDetails.MayEngineeringNum = yearPlanDetails.MayEngineeringNum;
                    yearPlanReviseDetails.MayMoneyNum = yearPlanDetails.MayMoneyNum;
                    yearPlanReviseDetails.JuneEngineeringNum = yearPlanDetails.JuneEngineeringNum;
                    yearPlanReviseDetails.JuneMoneyNum = yearPlanDetails.JuneMoneyNum;
                    yearPlanReviseDetails.JulyEngineeringNum = yearPlanDetails.JulyEngineeringNum;
                    yearPlanReviseDetails.JulyMoneyNum = yearPlanDetails.JulyMoneyNum;
                    yearPlanReviseDetails.AugustEngineeringNum = yearPlanDetails.AugustEngineeringNum;
                    yearPlanReviseDetails.AugustMoneyNum = yearPlanDetails.AugustMoneyNum;
                    yearPlanReviseDetails.SeptemberEngineeringNum = yearPlanDetails.SeptemberEngineeringNum;
                    yearPlanReviseDetails.SeptemberMoneyNum = yearPlanDetails.SeptemberMoneyNum;
                    yearPlanReviseDetails.OctoberEngineeringNum = yearPlanDetails.OctoberEngineeringNum;
                    yearPlanReviseDetails.OctoberMoneyNum = yearPlanDetails.OctoberMoneyNum;
                    yearPlanReviseDetails.NovemberEngineeringNum = yearPlanDetails.NovemberEngineeringNum;
                    yearPlanReviseDetails.NovemberMoneyNum = yearPlanDetails.NovemberMoneyNum;
                    yearPlanReviseDetails.DecemberEngineeringNum = yearPlanDetails.DecemberEngineeringNum;
                    yearPlanReviseDetails.DecemberMoneyNum = yearPlanDetails.DecemberMoneyNum;

                    //统计统计当前明细的EngineeringNum
                    if (statisticsItemMaintenance != null && !string.IsNullOrEmpty(statisticsItemMaintenance.EngineeringUnit as string))
                    {
                        string totalEngineeringNum = "0";
                        if (statisticsItemMaintenance.EngineeringUnit.Contains('/'))
                        {
                            totalEngineeringNum = "0/0";
                        }
                        CountEngineeringNumForDetails(yearPlanDetails.JanuaryEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.FebruaryEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.MarchEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.AprilEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.MayEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.JuneEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.JulyEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.AugustEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.SeptemberEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.OctoberEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.NovemberEngineeringNum, ref totalEngineeringNum);
                        CountEngineeringNumForDetails(yearPlanDetails.DecemberEngineeringNum, ref totalEngineeringNum);
                        if (totalEngineeringNum != "0" && totalEngineeringNum != "0/0")
                        {
                            yearPlanReviseDetails.TotalEngineeringNum = totalEngineeringNum;
                        }
                    }

                    //统计统计当前明细的MoneyNum
                    decimal totalMoneyNum = 0;
                    CountMonthMoneyNumForDetails(yearPlanDetails.JanuaryMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.FebruaryMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.MarchMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.AprilMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.MayMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.JuneMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.JulyMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.AugustMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.SeptemberMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.OctoberMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.NovemberMoneyNum, ref totalMoneyNum);
                    CountMonthMoneyNumForDetails(yearPlanDetails.DecemberMoneyNum, ref totalMoneyNum);
                    if (totalMoneyNum != 0)
                    {
                        yearPlanReviseDetails.TotalMoneyNum = totalMoneyNum.ToString();
                    }

                    YearPlanReviseDetailsRepository.Insert(yearPlanReviseDetails);
                }
                decimal totalMoney = totalJanuaryMoneyNum + totalFebruaryMoneyNum + totalMarchMoneyNum + totalAprilMoneyNum + totalMayMoneyNum + totalJuneMoneyNum + totalJulyMoneyNum + totalAugustMoneyNum + totalSeptemberMoneyNum + totalOctoberMoneyNum + totalNovemberMoneyNum + totalDecemberMoneyNum;

                yearPlanRevise.ProjectID = yearPlan.ProjectID;
                yearPlanRevise.ContractType = yearPlan.ContractType;
                yearPlanRevise.ContractID = yearPlan.ContractID;
                yearPlanRevise.YearPlanID = yearPlan.ID;
                yearPlanRevise.StatisticalCycle = yearPlan.StatisticalCycle;
                yearPlanRevise.Unit = yearPlan.Unit;
                yearPlanRevise.ReviseNum = GetNextOrderNo(yearPlan);
                yearPlanRevise.ReviseDate = DateTime.Now;
                yearPlanRevise.JanuaryMoneyNum = totalJanuaryMoneyNum.ToString();
                yearPlanRevise.FebruaryMoneyNum = totalFebruaryMoneyNum.ToString();
                yearPlanRevise.MarchMoneyNum = totalMarchMoneyNum.ToString();
                yearPlanRevise.AprilMoneyNum = totalAprilMoneyNum.ToString();
                yearPlanRevise.MayMoneyNum = totalMayMoneyNum.ToString();
                yearPlanRevise.JuneMoneyNum = totalJuneMoneyNum.ToString();
                yearPlanRevise.JulyMoneyNum = totalJulyMoneyNum.ToString();
                yearPlanRevise.AugustMoneyNum = totalAugustMoneyNum.ToString();
                yearPlanRevise.SeptemberMoneyNum = totalSeptemberMoneyNum.ToString();
                yearPlanRevise.OctoberMoneyNum = totalOctoberMoneyNum.ToString();
                yearPlanRevise.NovemberMoneyNum = totalNovemberMoneyNum.ToString();
                yearPlanRevise.DecemberMoneyNum = totalDecemberMoneyNum.ToString();
                yearPlanRevise.ReviseMoney = totalMoney.ToString();
                YearPlanReviseRepository.Insert(yearPlanRevise);
            }
        }

        private int GetNextOrderNo(YearPlan yearPlan)
        {
            int num = 1;
            IQueryable<YearPlanRevise> lstYearPlanRevise = YearPlanReviseRepository.Entities.Where(t => t.YearPlanID == yearPlan.ID);
            if (lstYearPlanRevise.Count() > 0)
            {
                object max = lstYearPlanRevise.Max(t => t.ReviseNum);

                if (max != null)
                {
                    num = Convert.ToInt32(max) + 1;
                }
            }
            return num;
        }


        #region 拨付款 支表二 图表部分里面的年度数据
        public List<PointView> GetYearPlanComplete(Guid projectID, Guid contractID, double totalReviseMoney)
        {
            List<PointView> lstPointView = new List<PointView>();
            List<YearPlanRevise> queryData = (from yp in YearPlanReviseRepository.Entities
                                              where yp.ProjectID == projectID && yp.ContractID == contractID && yp.StatisticalCycle.CompareTo("2017") < 0
                                              select yp).ToList();


            var statisticalCycle = from yp in queryData
                                   group yp by yp.StatisticalCycle into temp
                                   orderby temp.Key ascending
                                   select new { temp.Key };

            double total = 0;
            int count = 1;
            foreach (var year in statisticalCycle)
            {
                YearPlanRevise yearPlanRevise = queryData.Where(t => t.StatisticalCycle == year.Key).OrderByDescending(t => t.ReviseDate).FirstOrDefault();
                if (yearPlanRevise != null)
                {
                    if (Convert.ToInt32(year.Key) < 2014)
                    {
                        double reviseMoney = string.IsNullOrEmpty((yearPlanRevise.ReviseMoney as string)) ? 0 : Convert.ToDouble(yearPlanRevise.ReviseMoney);
                        total += reviseMoney;
                    }
                    else if (Convert.ToInt32(year.Key) == 2014)
                    {
                        if (count == 1)
                        {
                            AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 0, totalReviseMoney, ref total);
                        }
                        AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 1, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.FebruaryMoneyNum, lstPointView, 2, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MarchMoneyNum, lstPointView, 3, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AprilMoneyNum, lstPointView, 4, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MayMoneyNum, lstPointView, 5, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JuneMoneyNum, lstPointView, 6, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JulyMoneyNum, lstPointView, 7, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AugustMoneyNum, lstPointView, 8, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.SeptemberMoneyNum, lstPointView, 9, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.OctoberMoneyNum, lstPointView, 10, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.NovemberMoneyNum, lstPointView, 11, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.DecemberMoneyNum, lstPointView, 12, totalReviseMoney, ref total);
                    }
                    else if (Convert.ToInt32(year.Key) == 2015)
                    {
                        if (count == 1)
                        {
                            AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 0, totalReviseMoney, ref total);
                        }
                        AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 13, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.FebruaryMoneyNum, lstPointView, 14, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MarchMoneyNum, lstPointView, 15, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AprilMoneyNum, lstPointView, 16, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MayMoneyNum, lstPointView, 17, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JuneMoneyNum, lstPointView, 18, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JulyMoneyNum, lstPointView, 19, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AugustMoneyNum, lstPointView, 20, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.SeptemberMoneyNum, lstPointView, 21, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.OctoberMoneyNum, lstPointView, 22, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.NovemberMoneyNum, lstPointView, 23, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.DecemberMoneyNum, lstPointView, 24, totalReviseMoney, ref total);
                    }
                    else if (Convert.ToInt32(year.Key) == 2016)
                    {
                        if (count == 1)
                        {
                            AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 0, totalReviseMoney, ref total);
                        }
                        AddDictionary(yearPlanRevise.JanuaryMoneyNum, lstPointView, 25, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.FebruaryMoneyNum, lstPointView, 26, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MarchMoneyNum, lstPointView, 27, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AprilMoneyNum, lstPointView, 28, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.MayMoneyNum, lstPointView, 29, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JuneMoneyNum, lstPointView, 30, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.JulyMoneyNum, lstPointView, 31, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.AugustMoneyNum, lstPointView, 32, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.SeptemberMoneyNum, lstPointView, 33, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.OctoberMoneyNum, lstPointView, 34, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.NovemberMoneyNum, lstPointView, 35, totalReviseMoney, ref total);
                        AddDictionary(yearPlanRevise.DecemberMoneyNum, lstPointView, 36, totalReviseMoney, ref total);
                    }
                    count++;
                }
            }
            return lstPointView;
        }

        private void AddDictionary(string moneyNum, List<PointView> lstPointView, int x, double totalReviseMoney, ref double total)
        {
            double reviseMoney = string.IsNullOrEmpty((moneyNum as string)) ? 0 : Convert.ToDouble(moneyNum);
            total += reviseMoney;
            double proportion = Math.Round(total / totalReviseMoney * 100, 2);
            lstPointView.Add(new PointView() { X = x, Y = proportion });
        }
        #endregion

        #region 进度查询
        public string GetTotalReviseMoneyForMulContract(Guid projectID, string contractType, List<Guid> lstContractID)
        {
            decimal totalMoney = 0;
            foreach (Guid contractID in lstContractID)
            {
                TotalRevise totalRevise = TotalReviseRepository.Entities.Where(t => t.ProjectID == projectID && t.ContractType == contractType && t.ContractID == contractID).OrderByDescending(t => t.ReviseDate).FirstOrDefault();

                if (totalRevise != null && !string.IsNullOrEmpty(totalRevise.ReviseMoney))
                {
                    totalMoney += Convert.ToDecimal(totalRevise.ReviseMoney);
                }
            }
            return totalMoney == 0 ? string.Empty : totalMoney.ToString();
        }

        public List<PointView> GetYearPlanCompleteForMulContract(string projectID, string contractType, string contractIDSQLWhere, List<Guid> lstContractID, decimal totalReviseMoney)
        {
            string sql = @" select ID,ContractID,YearPlanID,StatisticalCycle,ReviseNum as ReviseNum into #temp from YearPlanRevises
                            where ProjectID='" + projectID + @"' and ContractType='" + contractType + @"' and ContractID in (" + contractIDSQLWhere + @") and StatisticalCycle<'2017'

                            select YearPlanID,MAX(ReviseNum) as ReviseNum into #temp1 from #temp
                            group by ContractID,YearPlanID,StatisticalCycle

                            select ID into #temp2 from YearPlanRevises as a
                            inner join #temp1 as b
                            on a.YearPlanID=b.YearPlanID and a.ReviseNum=b.ReviseNum

                            select  * from YearPlanRevises 
                            where ID in (SELECT ID FROM #temp2)

                            DROP TABLE #temp2 
                            DROP TABLE #temp1
                            DROP TABLE #temp";
            List<YearPlanRevise> queryData = DbSqlHelper<YearPlanRevise>.SqlQueryCommon(sql);

            var statisticalCycle = from yp in queryData
                                   group yp by yp.StatisticalCycle into temp
                                   orderby temp.Key ascending
                                   select new { temp.Key };

            List<PointView> lstPointView = new List<PointView>();
            decimal total = 0;
            int count = 1;
            foreach (var year in statisticalCycle)
            {
                List<YearPlanRevise> lstYearPlanRevise = queryData.Where(t => t.StatisticalCycle == year.Key).ToList();
                if (lstYearPlanRevise != null && lstYearPlanRevise.Count > 0)
                {
                    if (Convert.ToInt32(year.Key) < 2014)
                    {
                        foreach (YearPlanRevise yearPlanRevise in lstYearPlanRevise)
                        {
                            decimal reviseMoney = string.IsNullOrEmpty((yearPlanRevise.ReviseMoney as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.ReviseMoney);
                            total += reviseMoney;
                        }
                    }
                    else if (Convert.ToInt32(year.Key) == 2014)
                    {
                        ConstructDictionaryData(lstYearPlanRevise, totalReviseMoney, lstPointView, 0, count, ref total);
                    }
                    else if (Convert.ToInt32(year.Key) == 2015)
                    {
                        ConstructDictionaryData(lstYearPlanRevise, totalReviseMoney, lstPointView, 12, count, ref total);
                    }
                    else if (Convert.ToInt32(year.Key) == 2016)
                    {
                        ConstructDictionaryData(lstYearPlanRevise, totalReviseMoney, lstPointView, 24, count, ref total);
                    }
                    count++;
                }
            }
            return lstPointView;
        }

        private void ConstructDictionaryData(List<YearPlanRevise> lstYearPlanRevise, decimal totalReviseMoney, List<PointView> lstPointView, int monthNum, int count, ref decimal total)
        {
            decimal januaryMoneyTotal = 0;
            decimal februaryMoneyTotal = 0;
            decimal marchMoneyTotal = 0;
            decimal aprilMoneyTotal = 0;
            decimal mayMoneyTotal = 0;
            decimal juneMoneyTotal = 0;
            decimal julyMoneyTotal = 0;
            decimal augustMoneyTotal = 0;
            decimal septemberMoneyTotal = 0;
            decimal octoberMoneyTotal = 0;
            decimal novemberMoneyTotal = 0;
            decimal decemberMoneyTotal = 0;
            foreach (YearPlanRevise yearPlanRevise in lstYearPlanRevise)
            {
                decimal januaryMoney = string.IsNullOrEmpty((yearPlanRevise.JanuaryMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.JanuaryMoneyNum);
                januaryMoneyTotal += januaryMoney;

                decimal februaryMoney = string.IsNullOrEmpty((yearPlanRevise.FebruaryMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.FebruaryMoneyNum);
                februaryMoneyTotal += februaryMoney;

                decimal marchMoney = string.IsNullOrEmpty((yearPlanRevise.MarchMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.MarchMoneyNum);
                marchMoneyTotal += marchMoney;

                decimal aprilMoney = string.IsNullOrEmpty((yearPlanRevise.AprilMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.AprilMoneyNum);
                aprilMoneyTotal += aprilMoney;

                decimal mayMoney = string.IsNullOrEmpty((yearPlanRevise.MayMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.MayMoneyNum);
                mayMoneyTotal += mayMoney;

                decimal juneMoney = string.IsNullOrEmpty((yearPlanRevise.JuneMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.JuneMoneyNum);
                juneMoneyTotal += juneMoney;

                decimal julyMoney = string.IsNullOrEmpty((yearPlanRevise.JulyMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.JulyMoneyNum);
                julyMoneyTotal += julyMoney;

                decimal augustMoney = string.IsNullOrEmpty((yearPlanRevise.AugustMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.AugustMoneyNum);
                augustMoneyTotal += augustMoney;

                decimal septemberMoney = string.IsNullOrEmpty((yearPlanRevise.SeptemberMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.SeptemberMoneyNum);
                septemberMoneyTotal += septemberMoney;

                decimal octoberMoney = string.IsNullOrEmpty((yearPlanRevise.OctoberMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.OctoberMoneyNum);
                octoberMoneyTotal += octoberMoney;

                decimal novemberMoney = string.IsNullOrEmpty((yearPlanRevise.NovemberMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.NovemberMoneyNum);
                novemberMoneyTotal += novemberMoney;

                decimal decemberMoney = string.IsNullOrEmpty((yearPlanRevise.DecemberMoneyNum as string)) ? 0 : Convert.ToDecimal(yearPlanRevise.DecemberMoneyNum);
                decemberMoneyTotal += decemberMoney;
            }

            januaryMoneyTotal += total;
            if (count == 1)
            {
                AddDictionary(januaryMoneyTotal, totalReviseMoney, lstPointView, 0);
            }
            AddDictionary(januaryMoneyTotal, totalReviseMoney, lstPointView, monthNum + 1);

            februaryMoneyTotal += januaryMoneyTotal;
            AddDictionary(februaryMoneyTotal, totalReviseMoney, lstPointView, monthNum + 2);

            marchMoneyTotal += februaryMoneyTotal;
            AddDictionary(marchMoneyTotal, totalReviseMoney, lstPointView, monthNum + 3);

            aprilMoneyTotal += marchMoneyTotal;
            AddDictionary(aprilMoneyTotal, totalReviseMoney, lstPointView, monthNum + 4);

            mayMoneyTotal += aprilMoneyTotal;
            AddDictionary(mayMoneyTotal, totalReviseMoney, lstPointView, monthNum + 5);

            juneMoneyTotal += mayMoneyTotal;
            AddDictionary(juneMoneyTotal, totalReviseMoney, lstPointView, monthNum + 6);

            julyMoneyTotal += juneMoneyTotal;
            AddDictionary(julyMoneyTotal, totalReviseMoney, lstPointView, monthNum + 7);

            augustMoneyTotal += julyMoneyTotal;
            AddDictionary(augustMoneyTotal, totalReviseMoney, lstPointView, monthNum + 8);

            septemberMoneyTotal +=augustMoneyTotal;
            AddDictionary(septemberMoneyTotal, totalReviseMoney, lstPointView, monthNum + 9);

            octoberMoneyTotal +=septemberMoneyTotal;
            AddDictionary(octoberMoneyTotal, totalReviseMoney, lstPointView, monthNum + 10);

            novemberMoneyTotal +=octoberMoneyTotal;
            AddDictionary(novemberMoneyTotal, totalReviseMoney, lstPointView, monthNum + 11);

            decemberMoneyTotal += novemberMoneyTotal;
            AddDictionary(decemberMoneyTotal, totalReviseMoney, lstPointView, monthNum + 12);

            total = decemberMoneyTotal;
        }

        private void AddDictionary(decimal moneyNum, decimal totalReviseMoney, List<PointView> lstPointView, int x)
        {
            double proportion = (double)Math.Round(moneyNum / totalReviseMoney * 100, 2);
            lstPointView.Add(new PointView() { X = x, Y = proportion });
        }
        #endregion
    }
}